Convert Object to String using ObjectMapper

Problem: If you want to convert an Java object to a String using Java.

Solution: You just only have to initialize ObjectMapper and use writeValueAsString(<objectName>).

Example:

// Initialize ObjectMapper
ObjectMapper om = new ObjectMapper();

// Convert object to String
om.writeValueAsString(objectName);

Source: documentation

For more interesting tutorials & guides just check them HERE.

Leave a Reply

Your email address will not be published. Required fields are marked *