在Spring控制器中将Json属性与期间映射到类属性 [英] Map Json Property With Period To Class Property in Spring Controller
本文介绍了在Spring控制器中将Json属性与期间映射到类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个json对象被发送到控制器映射到类模型。 json包含以下属性
Event.GradeBook.GradeEvent:{}
我如何在类模型中表示它正确映射?
String Event_Gradebook_GradeEvent;
解决方案假设你使用Spring的默认Jackson反序列化,需要做的是用
@JsonProperty
注释您的字段。@JsonProperty (value =Event.GradeBook.GradeEvent)
private String Event_Gradebook_GradeEvent;
但你应该遵循Java的命名约定。
I have a json object being sent to a controller that maps to a class model. The json contains the property below
"Event.GradeBook.GradeEvent": { }
How can I represent this in a class model where it will map correctly?
String Event_Gradebook_GradeEvent;
解决方案Assuming you are using Spring's default Jackson deserialization, all you need to do is annotate your field with
@JsonProperty
.@JsonProperty(value = "Event.GradeBook.GradeEvent") private String Event_Gradebook_GradeEvent;
But you should really follow Java's naming conventions.
这篇关于在Spring控制器中将Json属性与期间映射到类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文