We are using JoiObjectMapper to convert a POJO class into Json String. Jackson version : 2.8.x The following is object mapper configuration :
import com.amazon.jacksonion.JoiObjectMapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
public static ObjectMapper createObjectMapper() {
ObjectMapper mapper = new JoiObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.registerModule(new JodaModule());
mapper.registerModule(new JavaTimeModule());
SimpleModule module = new SimpleModule();
module.addSerializer(new JavaUtilDateSerializer());
mapper.registerModule(module);
return mapper;
}
We are using objectMapper.writeValueAsString(object);
method to convert the POJO into Json.
@Data
public class POJO {
@JsonProperty("a")
private String a;
@JsonProperty("b")
private String b;
}
Issue: While converting to string the object mapper is removing the double quotes from Json Key values.
Actual Output :
{
a : "abc",
b : "cde"
}
Expected Output:
{
"a" : "abc",
"b" : "cde"
}
We need the json with double quotes. Can someone help us what are we missing here ??
I think you are looking for the boolean property JsonGenerator.Feature.QUOTE_FIELD_NAMES
. If I am remembering well it was true by default some years ago. Maybe this has changed now. Try to set it true
or false
to see if it works.