有什么办法可以更改方式。MAPFROM方法(在io.vertx.core.json.jsonobject中)正在通过对象mapper进行起作用还是可以模拟它?

发布于 2025-02-08 05:34:41 字数 1025 浏览 3 评论 0原文

我面临的错误是 java.lang.illegalargumentException:java 8日期/时间类型java.time.localdateTime default不支持:添加模块: -datatype-jsr310“为了启用处理,要解决此问题,我包括上面提到的依赖项,还进行了要注册的对象映射器中的更改(new Javatimemodule()),它在进行一些更改后正在工作(i Am编写测试)..

问题是我在使用 import ioo.vertx.core.json.json.jsonobject 的mapfrom方法的文件上使用的文件将java对象转换为json对象。班级),但是在这里没有objectmapper,要解决我必须使用okboctmapper的方法以获取jsonobject的错误,然后才能正常工作,但是我知道我无法对该文件进行任何更改(我是我是写作测试,我无法模拟jsonobject.mapfrom(类)

。我没有权限的主文件中的更改。。

我还可以直接在类上嘲笑该方法的任何方式?

这是代码: 在class1中:

Public void getSomething(Request request){
      JsonObject jsonObject = JsonObject.mapFrom(helper.class);
      //further use of json object

在辅助类中:

    public helper{
        LocalDateTime createdAt = LocalDate.now()
       //this is giving the Java 8, localDateTime error
    }

现在,我必须测试getomething,但是我无法模拟jsonobject.mapfrom(helper.class) 因此,我要么使用createAt上的注释,要么使用对象映射器将Java对象转换为JSON对象,然后解析,为此,我必须评论MAPFROM方法(我无法做到)。

The error i am facing is java.lang.IllegalArgumentException: Java 8 date/time type java.time.LocalDateTime not supported by default: add Module “com.fasterxml.jackson.datatype:jackson-datatype-jsr310” to enable handling , to resolve this i have included the dependency mentioned above and also made the changes in the object mapper to register(new javaTimeModule()), it is working after making some changes( i am writing tests)..

The problem is that the file i am working on converts java object to a JSon object using mapFrom method mentioned in import io.vertx.core.json.JsonObject like JsonObject.mapFrom(class) but the objectmapper is of no help here, to resolve the error i have to use a method from objectmapper to get the jsonObject then only it is working, but i came to know that i cannot make any change in that file( i am writing test and i cannot mock JsonObject.mapFrom(class). So, is there any way where i can change the way .mapFrom function is acting through objectmapper..

the error is also resolved by using annotations, but then also i have to make changes in main files which i don't have the permission for..

Also any way where i can mock such methods as it is being called on a class directly?

Here's the code:
In Class1:

Public void getSomething(Request request){
      JsonObject jsonObject = JsonObject.mapFrom(helper.class);
      //further use of json object

In helper class:

    public helper{
        LocalDateTime createdAt = LocalDate.now()
       //this is giving the Java 8, localDateTime error
    }

Now, i have to test getSomething, but i cannot mock the JsonObject.mapFrom(helper.class)
So either i am using annotations on CreatedAt or using object mapper to convert java object to json object with writeValueAsString then parsing and for this i have to comment the mapFrom method(which i can't do)..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仙气飘飘 2025-02-15 05:34:41

我只需使用模拟式的方法嘲笑JavaObject上的mapfrom方法来解决问题,另一个解决方案是更改主代码,以便它使用ObjectMapper将Java对象转换为JSONOBJECT,然后使用JSR310模块注册新的Javatimemememememememememememodules()...

I solved the issue by just mocking the mapFrom method on JavaObject using mockStatic, other solution was to change the main code such that it uses objectmapper to convert java object to jsonObject and then use the jsr310 module to register the new javaTimeModules()...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文