簡體   English   中英

JAVA僅針對特定ObjectMapper將地圖序列化為列表但

[英]JAVA serialize map as list BUT only for a specific ObjectMapper

有沒有一種方法可以將我的地圖序列化為json列表,但僅針對特定的ObjectMapper?

我用@JsonSerialize添加了我的自定義序列化類,它可以正常工作,但我只想將其用於特定的ObjectMapper。

  • 最初,第一個ObjectMapper必須將我的地圖序列化為json地圖
  • 第二個ObjectMapper必須使用我的自定義@JsonSerialize將地圖序列化為json列表

這可能嗎 ?

是的,這應該可行。 您需要為第二個ObjectMapper注冊一個模塊。

final SimpleModule module = new SimpleModule();
module.addSerializer(Map.class, new YourCustomSerializer());
module.addDeserializer(Map.class, new YourCustomDeserializer());

objectMapper.registerModule(module);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM