Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Alternative for deprecated JsonItemWriter

Avatar

Level 1

Hello everyone,

org.apache.commons.json.* has been deprecated since a long time and AEM has some better alternatives now. Since AEM 6.3, we are encouraged to use Gson or Jackson.

However, there has been no mention about JsonItemWriter and it's replacement. Can anyone please help me with the alternative for JsonItemWriter?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @sareshpp9060331 ,

 

We have been extensively using this class 

import com.google.gson.annotations

for json Serialization and Deserialization. This makes the code really short and clean and easy to understand.

You can refer to some examples here http://websystique.com/java/json/gson-json-annotations-example/

You also have the option to exclude any property from json by marking it as transient like this:

public class Flags {

private String flagText;
private String flagColor;
private transient String SourcePath;

It will generate:

"Flags": {"flagText": "United Kingdom","flagColor": "511E62"},

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @sareshpp9060331 ,

 

We have been extensively using this class 

import com.google.gson.annotations

for json Serialization and Deserialization. This makes the code really short and clean and easy to understand.

You can refer to some examples here http://websystique.com/java/json/gson-json-annotations-example/

You also have the option to exclude any property from json by marking it as transient like this:

public class Flags {

private String flagText;
private String flagColor;
private transient String SourcePath;

It will generate:

"Flags": {"flagText": "United Kingdom","flagColor": "511E62"},