
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 208 Articles for JSON

438 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, TYPE}) public @interface SinceExampleimport com.google.gson.annotations.Since; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class GsonSinceAnnotationTest { public static void main(String[] args) { Employee emp = new Employee(); emp.setEmployeeName("Raja Ramesh"); emp.setEmployeeId(125); emp.setEmployeeTechnology("Java"); emp.setEmploeeAddress("Hyderabad"); System.out.println("Since version ... Read More

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 web-services.Syntax@Documented @Retention(value=RUNTIME) @Target(value={FIELD, TYPE}) public @interface UntilExampleimport com.google.gson.annotations.Until; import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class GsonUntilAnnotationTest { public static void main(String[] args) { Employee emp = new Employee(); emp.setEmployeeName("Adithya"); emp.setEmployeeId(115); emp.setEmployeeTechnology("Python"); emp.setEmploeeAddress("Pune"); ... Read More

1K+ Views
In Java, Jackson is a library that is used to convert JSON to Java objects and vice versa. Jackson Annotations are used during serialization and deserialization. We use annotations with a particular field or method that is declared in Java. So, Annotations make the JSON output clearer as we required. In this Article, we will learn about one of its annotations @JsonRootName. @JsonRootName Annotatation The @JsonRootName annotation is a Jackson annotation that is used on a class if we want to do wrapping in our JSON attributes. It is a class-level annotation. It wraps the object to be serialized with a ... Read More

2K+ Views
In Java, Jackson is a library that is used to convert JSON to Java objects and vice versa. Jackson Annotations are used during serialization and deserialization to denote a particular field that is declared in Java as an instance variable, is a JsonProperty, and should be ignored. We can also use annotations with methods. So, basically, Annotations make JSON output clearer as we required. In this Article, we will learn about one of its annotations is @JsonRawValue Annotation. @JsonRawValue This annotation can be used for methods and fields. The @JsonRawValue annotation is used to serialize methods or fields as it ... Read More

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 void main(String[] args) { mployee emp = new Employee("Sai", "Ram", 30, "Bangalore"); JSONObject jsonObj = JSONObject.fromObject(emp); System.out.println(jsonObj.toString(3)); // pretty print JSON emp = (Employee)JSONObject.toBean(jsonObj, Employee.class); System.out.println(emp.toString()); } // Employee class public static ... Read More

1K+ Views
The @JsonFilter annotation belongs to Jackson Annotations. Jackson Annotations are used during serialization and deserialization to denote a particular field (or method) that is declared in Java as an instance variable, is a JsonProperty, and should be ignored, or what condition should be applied to it. It is used to define a dynamic filter for serializing/deserializing Java objects. @jsonfilter annotation Let's discuss the importance of jsonfilter annotation as given below - It is used to filter which fields or properties of an object should be included ... Read More

1K+ Views
Jackson Library: The @JsonView AnnotationIn Java, Jackson is a library that is used to convert JSON to Java objects and vice versa. Jackson Annotations are used during serialization and deserialization. We use these to denote or specify annotations before a particular field or method (that is declared in Java). Using an annotation before a field, we can denote whether a variable is a JsonProperty, should be ignored, or what condition should be applied to it. The JsonView annotation is used to include/exclude ... Read More

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 or false otherwise.Syntaxpublic void setJsonPropertyFilter(PropertyFilter jsonPropertyFilter)Exampleimport net.sf.json.JSONObject; import net.sf.json.JsonConfig; import net.sf.json.util.PropertyFilter; public class ConvertBeanToJsonExcludeFilterTest { public static void main(String[] args) { Student student = new Student("Sai", "Chaitanya", 20, "Hyderabad"); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new CustomPropertyFilter()); ... Read More

292 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 an argument to this method to disable the type hints in XML.Syntaxpublic void setTypeHintsEnabled(boolean typeHintsEnabled)Exampleimport net.sf.json.JSONObject; import net.sf.json.xml.XMLSerializer; public class ConvertBeanToXMLNoHintsTest { public static void main(String[] args) { Employee emp = new Employee("Krishna Vamsi", 115, 30, "Java"); JSONObject jsonObj = JSONObject.fromObject(emp); ... Read More

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 return a string representation of a well-formed XML document.Syntaxpublic String write(JSON json)Exampleimport net.sf.json.JSONObject; import net.sf.json.xml.XMLSerializer; public class ConvertBeanToXMLTest { public static void main(String[] args) { Student student = new Student("Sai", "Adithya", 25, "Pune"); JSONObject jsonObj = JSONObject.fromObject(student); System.out.println(jsonObj.toString(3)); //pretty print JSON ... Read More