使用Jackson将Json文件映射到POJO所需的@JsonProperty(@JsonProperty Required for Mapping Json File to POJO Using Jackson)
我有一个Java类文件,如下所示:
public class ToBeMapped { String value1; int value 2; }
然后我有一个名为“test.json”的JSON文件,如下所示:
{ "value1": "hellow world", "value2": 12345 }
然后我尝试将JSON文件映射到另一个Java文件中的“TobeMapped”对象:
public class Testing { public void justTesting() throws IOException { ToBeMapped temp = new ObjectMapper().readValue(new File("path/to/test.json"), ToBeMapped.class); } }
这会给我以下错误:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "value1" ...
如果我在每个类变量之前添加
@JsonProperty
,我可以将JSON文件映射到POJO而没有任何错误。public class ToBeMapped { @JsonProperty String value1; @JsonProperty int value 2; }
为了让Jackson的映射器将JSON文件/流映射到对象,我是否必须将此标头添加到每个类变量中? 或者我在代码中遗漏了一些东西?
谢谢。
I have a Java class file that looks like following:
public class ToBeMapped { String value1; int value 2; }
Then I have a JSON file, named "test.json", looks like following:
{ "value1": "hellow world", "value2": 12345 }
Then I try to map the JSON file to "TobeMapped" object in another Java file:
public class Testing { public void justTesting() throws IOException { ToBeMapped temp = new ObjectMapper().readValue(new File("path/to/test.json"), ToBeMapped.class); } }
This will give me the following error:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "value1" ...
If I add the
@JsonProperty
before each class variable as below, I can map the JSON file to the POJO without any errors.public class ToBeMapped { @JsonProperty String value1; @JsonProperty int value 2; }
Is it true that I have to add this header to each class variable in order for Jackson's mapper to map the JSON file/stream to the object? Or I'm missing something in my code?
Thanks.
原文:https://stackoverflow.com/questions/49076059
最满意答案
您可以使用此插件: http : //nsis.sourceforge.net/StdUtils_plug-in ,查看InvokeShellVerb部分文档: http : //muldersoft.com/docs/stdutils_readme.html
You can use this plugin: http://nsis.sourceforge.net/StdUtils_plug-in, Review InvokeShellVerb section documentation: http://muldersoft.com/docs/stdutils_readme.html
相关问答
更多-
如何将Spring Tool Suite固定到Windows 7任务栏[关闭](How to pin Spring Tool Suite to Windows 7 taskbar [closed])[2022-01-28]
我在Windows 7上使用了STS 3.2.0-RELEASE的x64版本,这个问题对我来说也是如此: 检查你的eclipse.ini ,并确保VM路径指向JDK或JRE的bin目录, 而不是javaw.exe 。 对我来说,参数是D:/Development/Languages/Java/Development Kit/bin/ 从任务栏取消固定Eclipse或删除快捷方式 从Windows资源管理器运行eclipse.exe并选择您的工作区 启动屏幕已加载并显示主窗口后,将Eclipse引导至任务栏 ... -
你可以用窗口聚焦 window.focus() 但这并不总是奏效。 让任务栏图标闪烁的可能性不可用。 You can focus the window with window.focus() But that does not always work. The possibility to let the taskbar icon blink is not available.
-
您无法固定子窗口 - 在应用程序级别固定工作。 如果你固定/取消固定子窗口,你就可以(取消)固定整个应用程序。 没有办法禁用此行为,因为它的操作系统级功能适用于任务栏中的任何窗口(尽管您可以选择不在任务栏中显示这些窗口)。 我不确定Window图标,但是当你说它只是使用应用程序图标时,我想你是对的。 You can't pin a child window - pinning works at the level of the application. If you pin/unpin a child wi ...
-
是否有用于向任务栏图标添加徽章的Windows API?(Is there a Windows API for adding badges to taskbar icons?)[2022-08-29]
ITaskBarList3::SetOverlayIcon是您正在寻找的。 ITaskBarList3::SetOverlayIcon is what you're looking for. -
使用Advanced Installer将程序固定到任务栏[关闭](Pin a program to the taskbar using Advanced Installer [closed])[2022-07-24]
OD是对的, Microsoft不建议在Win 7的任务栏中自动固定 ,这就是为什么该功能从未在Advanced Installer中实现的原因。 但是,如果可能,以编程方式固定,如链接文章中所示。 您所要做的就是在安装过程结束时将代码添加为自定义操作,因此可以在安装程序创建快捷方式后固定快捷方式。 O.D. is right, Microsoft does not recommend automatic pinning in the task bar for Win 7, this is why the ... -
创建图形时,将WindowStyle属性设置为docked : for k = 1:10 figure('WindowStyle','docked'); end 这样,所有图形都将在主Matlab窗口中的不同选项卡中打开,因此您不会在任务栏中看到它们。 请参阅下面的底部任务栏的peek-view,它只预览了2个窗口。 接下来,您可以在“图”窗口中选择“浮动”选项: 然后你可以按照自己的意愿安排所有的数字: When you create the figures, set the WindowSty ...
-
将图标固定到任务栏(Pin icons to taskbar)[2022-03-13]
您可以使用此插件: http : //nsis.sourceforge.net/StdUtils_plug-in ,查看InvokeShellVerb部分文档: http : //muldersoft.com/docs/stdutils_readme.html You can use this plugin: http://nsis.sourceforge.net/StdUtils_plug-in, Review InvokeShellVerb section documentation: http://m ... -
桌面频带在Windows上并没有完全消失,但它们仍然支持生命。 首先确保您不想利用缩略图工具栏,ITaskbarList3 :: ThumbBarXxx()函数。 我不知道api会回读按钮大小设置。 您可以使用后门,这些配置设置始终保存到注册表中。 运行SysInternals的ProcMon实用程序并更改设置。 在我的机器上(Windows 8),弹出这个注册表项: HKEY_CURRENT_USER \软件\微软\的Windows \ CurrentVersion \ Explorer中\高级\ Tas ...
-
感谢蒂姆·威廉姆斯在上面的评论中,我能够获得一个VBA代码来添加/删除可以固定和取消固定项目的注册表项。 If RegKeyExists("HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\BEApplication\") = False Then ' Code for adding registry key Dim myWS As Object, st ...
-
每次更新后决定重新启动。 Decided to reboot after each update.