Jackson serializer for primitive types

后端 未结 2 437
鱼传尺愫
鱼传尺愫 2020-12-20 01:01

I am writing a custom serializer to convert double values into strings in JSON objects. My code so far:

public String toJson(Object obj) throws IOException {         


        
2条回答
  •  抹茶落季
    2020-12-20 01:39

    You can do it with custom serializer, but there is a simpler way to. Enable JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS:

    mapper.getFactory().enable(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS);
    

提交回复
热议问题