サンプルクラスがあります
public class Category {
private String id ;
private String name ;
private String description ;
private String image ;
private String thumbnail ;
private Map<String, String> custom ;
}
以下の形式でサーバーからの応答がありますが、例として、これがファイル cat.json にあるとしましょう
{"id":"mens","name":"Mens","c__showInMenu":true,"c__enableCompare":false}
1 ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
2 Category cat= mapper.readValue(new File("cat.json"), Category.class);
これは、id、name などのフィールドに対して完全に正常に機能します。 で始まる json のフィールドがc_
Map カスタムにプッシュされるように、カスタム デシリアライザーを作成するにはどうすればよいですか?
私はJacksonを初めて使用し、Springs Rest Templateを使用しており、使用するように構成しています
org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
.