
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 9150 Articles for Object Oriented Programming

7K+ Views
Jackson is a library that allows you to convert Java objects into XML and vice versa. In this example, we will demonstrate how to convert a POJO (Plain Old Java Object) into XML using the Jackson library. Well, if you are not familiar with POJO, it is a simple Java object that does not follow any specific framework or design pattern. It is just a regular Java class with fields and methods. We will use the method writeValueAsString() of the XmlMapper class to convert a POJO into XML. The XmlMapper class is part of the Jackson library and it ... Read More

1K+ Views
Parsing a JSON without duplicate keys means converting a JSON string into a Java object. But we need to keep in mind that the JSON string should not have duplicate keys. Gson: Parsing a JSON Without Duplicate Keys We can use the Gson library to parse a JSON without duplicate keys in Java. It is developed by Google and used for converting Java objects into JSON and vice versa. By default, Gson does not allow duplicate keys in JSON. If a JSON string has duplicate keys, Gson will throw a JsonSyntaxException. We will use the methods fromJson() and toJson() to achieve ... Read More

1K+ Views
Array is a container of elements of Same data types length needs to be defined beforehand. And an element can appear in any order and any number of times in an array. so in this program we will find elements that appear more than once in an array.Problem description − We have given an array arr[] in which we have to find which of the element are repeating in the array an app to print them.Let’s take an example to understand this better.Example, Input: arr[] = {5, 11, 11, 2, 1, 4, 2} Output: 11 2ExplanationWe have an array arr ... Read More

3K+ Views
Jackson is a Java-based library, and it can be useful to convert Java objects to JSON and JSON to Java objects. A Jackson API is faster than other API, needs less memory, and is good for large objects. We can format a date using the setDateFormat() of ObjectMapper class. This method can be used for configuring the default DateFormat when serializing time values as Strings and deserializing from JSON Strings. Syntax of setDateFormat() public ObjectMapper setDateFormat(DateFormat df) Here, df is the DateFormat instance to be used for formatting dates. Steps to format a date using Jackson in Java Following ... Read More

382 Views
Serializing a Map in Java is the process of converting a Map object into a format that can be easily stored or transmitted, such as JSON or XML. We will use the Flexjson library to serialize a map in Java. We can serialize a Map using the serialize() method of the JSONSerializer class, which performs a shallow serialization of the target instance. Example of Serializing a Map We will take a map and see the output after serialization. Map map = new HashMap(); map.put("name", "Ansh"); map.put("age", "23"); map.put("city", "Mumbai"); map.put("country", "India"); After serialization, the map will look like this: {"name":"Ansh", ... Read More

2K+ Views
The FieldNamingPolicy can be used to define a few standard naming conventions for JSON field names and it can be used in conjunction with GsonBuilder to configure a Gson instance to properly translate Java field names into the desired JSON field names. We can use the setFieldNamingPolicy() method of GsonBuilder to configure a specific naming policy strategy to an object's field during serialization and deserialization.Gson supports various field naming requirements with following field naming policiesFieldNamingPolicy.IDENTITY: It uses the exact same naming as the Java model when it serializes an object.FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES: It modifies a Java field name from its camel-cased form to a lower case field name where ... Read More

701 Views
Serialization is the process that converts an object into a format that can be stored or transmitted easily. Excluding a Field in Gson During Serialization We might have some scenarios where we are asked or required to exclude a certain field from the object while serializing it. For example, we have a Student object with fields like name, age, and address. We want to serialize the object but exclude the address field for building basic information about the student in this case, we use In this article, we will learn how to exclude a field in Gson during serialization ... Read More

5K+ Views
Gson is a Java library which is developed by Google and used to convert Java objects into JSON and vice versa. It is mostly used in applications where data can be exchanged in JSON format. There are two useful methods in Gson that we are going to discuss in this article. These methods are fromJson() and toJson(). The fromJson() Method The fromJson() method is used to convert a JSON string into a Java object. It takes two parameters: the JSON string and the class type of the object you want to create. Here is the syntax of the fromJson() method: ... Read More

452 Views
Serialization is the process where we convert an object into a format that can be easily stored or transmitted and later reconstructed. The given task is to serialize an array of objects using Flexjson in Java. Serializing an Array of Objects Using Flexjson Flexjson is a lightweight Java library for serializing and deserializing java beans, maps, arrays, and collections in JSON format. We can also deserialize a JSON string to an existing object using the deserializeInto() method of the JSONDeserializer class, this method deserializes the given input into the existing object target. The values in the JSON input can overwrite ... Read More

3K+ Views
Deserialization is the process of converting a JSON string into a Java object. In this example, we will learn how to deserialize a JSON string into an existing object in Java. There are libraries available in Java that can help us to deserialize a JSON string into an existing object. Some of the popular libraries are: Using Gson Using Jackson Using Flexjson Let's learn how to use each of these libraries to deserialize a JSON string into an existing object in Java. Deserializing JSON Object Using ... Read More