When we have a JSON object and want to change a specific field name for some reason, we can use the Jackson library in Java.The Jackson Annotation @JsonProperty The Jackson Annotation @JsonProperty is used on a property or method during the serialization or deserialization of JSON. It takes an optional 'name' parameter, which is useful in case the property name is different from the key name in JSON. By default, if the key name matches the property name, the value is mapped to the property value. If the key name is different, we can use the @JsonProperty annotation to ... Read More
Sometimes we need to exclude certain fields from the JSON output. For example, if we have a field that contains sensitive information, we may not want to include it in the JSON representation of the object. In such cases, we can use the Expose annotation provided by Gson. The Gson @Expose annotation The Gson @Expose annotation can be used to specify whether a field isto be exposed or not (included or not). The @Expose annotation can take two parameters, and each parameter is a boolean which can take either the value true or false. The two parameters are: ... Read More
An Iterator is used for cycling through a Collection of objects. Whereas a List is an Interface which is used for storing an ordered collection of elements. Both classes are part of the Java Collections Framework.Converting an Iterator to a List in Java Sometimes we need to convert an Iterator to a collection. In this article, we will learn how to convert an Iterator to a List in Java using multiple ways. Those are: Using a while loop Using Iterator.forEachRemaining() Using Stream API Let's understand each of them in ... Read More
What is an Iterable?Iterable is an Interface that is used for iterating over a Collection of objects. It is part of the Java Collections Framework. The Iterable interface is implemented by all the collection classes in Java. For example, ArrayList, HashSet, etc. The Iterable interface has a method named iterator() which returns an Iterator object.What is a Stream? Stream is an Interface that is used for processing sequences of elements. It is part of the Java Collections Framework. The Stream interface is a newly added abstraction in Java 8. It is mainly used for sequential operations on collections, for example, ... Read More
In Java, we can store objects within other objects. A collection is an object that stores other objects. Some examples of collections are ArrayList, HashSet. Iterable is an Interface that is used for iterating over a Collection of objects. It is part of the Java Collections Framework. The Iterable interface is implemented by all the collection classes in Java. The Iterable interface has a method named iterator() which returns an Iterator object. In this article, we will learn how to convert an Iterable to a Collection in Java using multiple ways. Those are - Using for-each ... Read More
While developing Java Swing applications, you may have cases when you need to modify the space around JButtons to develop attractive applications. In this article, we will learn to set the margin of a JButton in Java. What is a JButton? A JButton is a subclass of AbstractButton, and it can be used for adding platform-independent buttons to a Java Swing application. A Button can generate an ActionListener interface when the button is pressed or clicked, it can also generate the MouseListener and KeyListener interfaces. Syntax The following is the syntax for JButton initialization: JButton button = new JButton("Button"); We ... Read More
When you have to show long text messages, you might find problems with the dialog becoming too big or the text getting cut off. In this article, we will learn to implement a long text of the JOptionPane message dialog in Java. What is a JOptionPane? A JOptionPane is a subclass of the JComponent class, which includes static methods for creating and customizing modal dialog boxes. A JOptionPane class can be used instead of a JDialog class to minimize the complexity of the code. Syntax The following is the syntax for JOptionPane initialization: JOptionPane.showMessageDialog(null, "Tutorials Point"); The JOptionPane displays the ... Read More
Try-catch, throw, and throws are keywords that are used for handling exceptions in Java. Exceptions are the problems that occur during the execution of a program. When a problem occurs, the program you are trying to run will terminate abnormally. So, to handle these exceptions, Java has a mechanism called exception handling. We handle different types of exceptions, such as runtime exceptions, compile-time exceptions, using try-catch, throw, and throws keywords. Types of Exceptions There are two types of exceptions in Java: Checked Exceptions: These are the exceptions that are checked at compile time. For example, ClassNotFountException, ... Read More
A Jackson API 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 process a JSON in three different ways: Streaming API, Tree Model, and Data Binding. We can pretty print JSON using the writerWithDefaultPrettyPrinter() of the ObjectMapper class, which is a factory method for constructing an ObjectWriter that will serialize objects using the default pretty printer for indentation. In this article, we will learn how to pretty print JSON using the Jackson ... Read More
JSON is a format that is used to exchange data between a server and a client. It is lightweight and easy to read and write. In Java, we can convert JSON to/from Map using various libraries. In this article, we will discuss how to convert JSON to/from Map using the Jackson library. The Jackson is a library for Java, and it has very powerful data binding capabilities and provides a framework to serialize custom java objects to JSON and deserialize JSON back to Java object. We can convert JSON to/from Map using readValue() and writeValueAsString() methods of com.fasterxml.jackson.databind.ObjectMapper class. To ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP