流形 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 (将#修改为@)