Serialize Object to String in Java: Base64 and JSON
Serialize object to String in Java with ObjectOutputStream and Base64 or with Jackson JSON, read it back, and avoid the deserialization security risk.
Serialize object to String in Java with ObjectOutputStream and Base64 or with Jackson JSON, read it back, and avoid the deserialization security risk.
Learn to create custom Jackson serializers and deserializers, register using the SimpleModule as well as @JsonSerialize and @JsonDeserialize.
By default, Jackson serializes the Dates in numeric format. Learn to customize the serialization and deserialization of date and time types in Java using Jackson.
Learn Jackson’s default serialization and deserialization of boolean values, and how to customize it to support other possible values.
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 …
Fix TypeError Object is not JSON serializable in Python with a default function, a JSONEncoder subclass, dataclasses.asdict() or __dict__, with dates.
Learn to use custom serialization and deserialization using two interfaces Gson JsonSerializer and JsonDeserializer to convert between json and java object.
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 …
Serialize an ArrayList to a file or a byte array with ObjectOutputStream, read it back with ObjectInputStream, handle the unchecked cast, and see when JSON with Jackson is the better choice.
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 …
This Java tutorial uses JAXB and MOXy to marshal Java objects to JSON string or write JSON to file using simple examples.
Java custom serialization with private readObject() and writeObject(), defaultWriteObject(), validation after reading, readResolve() and records.
Use XMLEncoder and XMLDecoder to save Java objects as XML, handle errors with ExceptionListener, store records and avoid decoding untrusted XML.
Externalizable vs Serializable in Java with a runnable example, constructor rules, read order, real size numbers, versioning, records and security.
Learn the Java transient keyword with serialization examples, restoring fields in readObject(), static and final transient fields, Jackson, Gson and JPA.
Learn to convert JSON to Map and convert a Map to JSON string using Jackson 2. Given example uses Jackson ObjectMapper for conversions.
The serialVersionUID versions a Serializable class in Java. See the declaration rules, InvalidClassException, the computed default, serialver and records.
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 …
Learn to write a List or Set to XML with Jakarta XML Binding 4 and read it back. We put the list in a root class, see why a bare List fails, and cover Set order, a Map and empty or null lists.
Java deep copy using in-memory serialization with a generic helper, shared references, transient fields, SerializationUtils, real cost and alternatives.
Java serialization explained with Serializable, serialVersionUID, transient fields, records, readObject, Externalizable and deserialization filters.
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.
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.