Several Internet posts point to Jackson as a better syntax performance than GSON, providing somewhere around 20-30% speed improvement.
Pulling out our GSON parser and replacing it, Jackson led to a slowdown of 7 times in my project with a delay of more than 300 ms per call. The same parsing action on GSON takes less than 50 ms.
I looked at the gotchas list on Wiki Jackson, but nothing stood out like a red flag.
For example, I do not recreate my ObjectMapper , and I use ObjectReader to read all JSON. Here is a sample code:
public class JsonParser { @Nonnull private final ObjectMapper objectMapper; public JsonParser() { final ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setDateFormat(DateFormatUtil.getGmtIso8601DateFormat()); SimpleModule simpleModule = new SimpleModule(); objectMapper.registerModule(simpleModule); this.objectMapper = objectMapper; } public <T> T fromJson(InputStream inputStream, Class<T> clazz) throws IOException { ObjectReader reader = objectMapper.reader(clazz); return reader.readValue(inputStream); } }
The object above is created once and is used throughout the application to translate JSON to POJO. An example of POJO can be seen here:
@JsonSerialize(include= Inclusion.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) public class ActivityEntity { public ActivityObjectEntity actor; public ActivityObjectEntity object; public ActivityObjectEntity provider; public ActivityObjectEntity target; public ActivityObjectEntity generator; public String content; public String title; public String verb; public String url; public Date published; public Date updated;
What is serialized is actually a list of the above items.
Here are my examples of trace windows from each run. Notice this is not an anomaly. I sequentially get the same performance order as Gson and Jackson by analyzing the same dataset.
The comparison was with Jackson 2.4.2 and Gson 2.2.4


source share