Java Serialization

Lombok Serialize and Deserialize @Builder Class

Lombok @Builder generates a builder for our class, and Gson serializes and deserializes such a class without extra configuration, whereas Jackson serializes it directly but needs @Jacksonized or @JsonDeserialize to deserialize it. Serialization converts a Java object to JSON, and deserialization converts the JSON back to a Java object. We …

Gson – Serialize and Deserialize a Map

Learn to serialize HashMap using Google Gson library. Also, learn to deserialize JSON string to HashMap containing custom Objects using Gson such that field values are copied into appropriate generic types. These conversions can be used to create deep cloning of the HashMap. 1. Maven Include the latest version of …

JAXB Marshaller Example: Converting POJO to XML

The JAXB Marshaller interface is responsible for governing the process of serializing Java content trees i.e. Java objects to XML data. This marshalling from POJO to XML can be done to a variety of output targets. 1. Maven Start with adding the latest ‘jakarta‘ dependencies for adding the JAXB support …

JAXB: Marshal / Unmarshal a Map in Java

We know that JAXB(Java Architecture for XML Binding) allows Java developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects. JAXB mostly is used while implementing webservices or …

How to Clone an Object in Java: Shallow vs Deep Copy

Clone an object in Java with Cloneable and clone() or, better, with a copy constructor. Learn shallow vs deep copy, cloning arrays and collections, deep copies with serialization and Jackson, and why records need no cloning.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.