Jackson:将带有标签列表的对象序列化

huangapple 未分类评论65阅读模式
标题翻译

Jackson: Serializing object with list of tags

问题

  1. {
  2. "SnapshotIdentifier": 'rs:dnd-1',
  3. "ClusterIdentifier": 'dnd-1',
  4. "SnapshotCreateTime": '2020-03-03T17:58:46.173Z',
  5. "SnapshotType": 'automated',
  6. "Status": 'available',
  7. "Tags": [{ "Key": "test", "Value": "my-tag" }] //<--- need to convert `Key` and `Value` to capitalized just like other properties
  8. }
英文翻译

I'm trying to serialize Java POJO into Json with capitalized property names. I'm using @JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class) for that and for the most part its working correctly except for Tags list. The the property names are still coming as lower case. What do I need to make them capitalized?

  1. @JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
  2. public class Snapshot implements Serializable {
  3. private String snapshotIdentifier;
  4. private String clusterIdentifier;
  5. private Date snapshotCreateTime;
  6. private String snapshotType;
  7. private String status;
  8. private List&lt;Tag&gt; tags;
  9. ...
  10. ...

ex:

  1. {
  2. SnapshotIdentifier: &#39;rs:dnd-1&#39;,
  3. ClusterIdentifier: &#39;dnd-1&#39;,
  4. SnapshotCreateTime: &#39;2020-03-03T17:58:46.173Z&#39;,
  5. SnapshotType: &#39;automated&#39;,
  6. Status: &#39;available&#39;,
  7. Tags: [{ key: &quot;test&quot;, value: &quot;my-tag&quot; }] &lt;--- need to convert `key` and `value` to capitalized just like other properties
  8. },

huangapple
  • 本文由 发表于 2020年3月4日 05:29:59
  • 转载请务必保留本文链接:https://java.coder-hub.com/60515820.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定