Raja has Published 469 Articles

Importance of @JsonIdentityInfo annotation using Jackson in Java?

raja

raja

Updated on 09-Jul-2020 05:13:16

1K+ Views

The @JsonIdentityInfo annotation is used when an object has a parent-child relationship in the Jackson library. The @JsonIdentityInfo annotation is used to indicate the object identity during the serialization and deserialization process. The ObjectIdGenerators.PropertyGenerator is an abstract place-holder class to denote a case where Object Identifier to use comes from a POJO property.Syntax@Target(value={ANNOTATION_TYPE, TYPE, ... Read More

How to convert a JSON array to array using JSON-lib API in Java?

raja

raja

Updated on 08-Jul-2020 12:53:38

2K+ Views

The JSONArray is a sequence of values, the external text is a string enclosed in square brackets with commas separating the values and internal text is an object having get() and opt() methods, we need to access those values by index. The element() method for adding or replacing those values. An array is ... Read More

How can we use @Since annotation using Gson in Java?

raja

raja

Updated on 08-Jul-2020 12:38:47

439 Views

The @Since annotation can use with the setVersion() method of the GsonBuilder class. This annotation can apply to a field in java class and accepts float as an argument. This argument represents the version number in which the field has serialized. The same can apply to the deserialization process.Syntax@Documented @Retention(value=RUNTIME) @Target(value={FIELD, ... Read More

How to use @Until annotation using the Gson library in Java?

raja

raja

Updated on 08-Jul-2020 12:01:11

350 Views

The @Until annotation can use with the setVersion() method of the GsonBuilder class. This annotation can apply to a field in java class and accepts float as an argument. This argument represents the version number in which the field has serialized. The @Until annotation can manage the versioning of JSON classes in ... Read More

How to convert the JSON object to a bean using JSON-lib API in Java?

raja

raja

Updated on 08-Jul-2020 11:34:52

3K+ Views

The JSONObject class is a collection of name/value pairs (unordered) where the bean is a class with setter and getter methods for its member fields. We can convert a JSON object to a bean using the toBean() method of JSONObject class.Syntaxpublic static Object toBean(JSONObject jsonObject, Class beanClass)Exampleimport net.sf.json.JSONObject; public class ConvertJSONObjToBeanTest {    public static ... Read More

How to convert a bean to XML without type hints using JSON-lib API in Java?

raja

raja

Updated on 08-Jul-2020 11:20:50

295 Views

The JSON-lib is a Java library for serializing and de-serializing java beans, maps, arrays, and collections in JSON format. We can convert a bean to XML without type hints using the setTypeHintsEnabled() method of XMLSerializer class, this method sets whether JSON types can be included as attributes. We can pass false as ... Read More

How to convert a bean to JSON object using Exclude Filter in Java?

raja

raja

Updated on 08-Jul-2020 11:20:06

481 Views

The JsonConfig class can be used to configure the serialization process. We can use the setJsonPropertyFilter() method of JsonConfig to set the property filter when serializing to JSON. We need to implement a custom PropertyFilter class by overriding the apply() method of the PropertyFilter interface. It returns true if the property will be filtered out ... Read More

How to convert a bean to XML using JSON-lib API in Java?

raja

raja

Updated on 08-Jul-2020 11:16:03

355 Views

The net.sf.json.xml.XMLSerializer class is a utility class for transforming JSON to XML. When transforming JSONObject instance to XML, this class can add hints for converting back to JSON. We can use the write() method of XMLSerializer class to write a JSON value into an XML string with UTF-8 encoding and it can ... Read More

How to convert bean to JSON object by excluding some properties using JsonConfig in Java?

raja

raja

Updated on 08-Jul-2020 09:05:50

1K+ Views

The JsonConfig class is a utility class that helps to configure the serialization process. We can convert a bean to a JSON object with few properties that can be excluded using the setExcludes() method of JsonConfig class and pass this JSON config instance to an argument of static method fromObject() of JSONObject.Syntaxpublic void setExcludes(String[] ... Read More

How to convert a Map to JSON object using JSON-lib API in Java?

raja

raja

Updated on 08-Jul-2020 08:20:25

6K+ Views

A JSONObject is an unordered collection of name/value pairs whereas Map is an object that maps keys to values. A Map cannot contain duplicate keys and each key can map to at most one value. We need to use the JSON-lib library for serializing and de-serializing a Map in JSON format. Initially, we can create ... Read More

Advertisements