Alternative for deprecated JsonItemWriter

sareshpp9060331

24-07-2020

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?

Accepted Solutions (1)

Accepted Solutions (1)

ChitraMadan

MVP

25-07-2020

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"},