Alternative for deprecated JsonItemWriter | Community
Skip to main content
sareshpp9060331
July 25, 2020
Solved

Alternative for deprecated JsonItemWriter

  • July 25, 2020
  • 2 replies
  • 1950 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ChitraMadan

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

2 replies

Vaibhavi_J
Level 7
July 25, 2020
ChitraMadan
Community Advisor
ChitraMadanCommunity AdvisorAccepted solution
Community Advisor
July 25, 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"},