微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

流形 load().fromJson() 抛出 java.lang.ClassCastException

如何解决流形 load().fromJson() 抛出 java.lang.ClassCastException

我按照 https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-json 下的文档部署了一个 jar,它只提供 User 类,使用记录的 Maven 编译插件

<build>
    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
        <compilerArgs>
            <!-- Configure manifold plugin-->
            <arg>-Xplugin:Manifold</arg>
            <arg>-Amanifold.source.json=^com\.example\.schemas\.User$</arg>
        </compilerArgs>
        <!-- Add the processor path for the plugin (required for Java 9+) -->
        <annotationProcessorPaths>
            <path>
            <groupId>systems.manifold</groupId>
            <artifactId>manifold-json</artifactId>
            <version>2020.1.44</version>
            </path>
        </annotationProcessorPaths>
        </configuration>

我的另一个项目使用这个包作为依赖,下面的代码工作正常:

import com.example.schemas.User;
...

User user = User.builder("Scott McKinney","scott@manifold.systems")
  .build();

但这会引发异常:

User user = User.load().fromJson("{\"name\": \"Scott McKinney\",\"email\": \"scott@manifold.systems\"}");

java.lang.classCastException: class manifold.json.rt.api.DataBindings 
  cannot be cast to class com.example.schemas.User (manifold.json.rt.api.DataBindings 
  and com.example.schemas.User are in unnamed module of loader 'app')

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。