public class Statics {
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Double sum;
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Double avg;
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Double max ;
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Double min ;
    private Long count = Long.valueOf(0);
}

Using this annotation: @JsonFormat(shape = JsonFormat.Shape.STRING) Solved my problem!

Answer from Nejatians on Stack Overflow
๐ŸŒ
MangoHost
mangohost.net โ€บ mangohost blog โ€บ java convert double to string โ€“ methods and examples
Java Convert Double to String โ€“ Methods and Examples
August 3, 2025 - When building REST APIs, you often need to format numerical data for JSON responses: import com.fasterxml.jackson.databind.ObjectMapper; import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; public class ApiResponseExample { public static void main(String[] args) throws Exception { double price = 99.999; double discount = 0.15; // Format for financial data (2 decimal places) DecimalFormat currency = new DecimalFormat("0.00"); DecimalFormat percentage = new DecimalFormat("0.0%"); Map
Top answer
1 of 4
2

You can create a custom Deserializer to deserialize the Message text into Message object and annotate the Message class with @JsonDeserialize:

@JsonDeserialize(using = MessageDeserializer.class)
public class Message {
    String language;
    String data;
}

public class MessageDeserializer extends JsonDeserializer<Message> {

    public MessageDeserializer() {
        super();
    }

    @Override
    public Message deserialize(
            final JsonParser jsonParser, final DeserializationContext deserializationContext) throws
            IOException, JsonProcessingException {
        final String messageText = jsonParser.getText(); 
        // parse messageText into Message object
    }
}
2 of 4
1

I am not sure my solution is acceptable since it does require additional explicit call to ObjectMapper to perform deserialization of the string value of Message.
However, this is it is done during the buildup of Notification object and does not require a String message property.

You need to add a ctor with String argument to Message class, where you can deserialize the String into Map and extract the instance propertieds:

public Message(String str) {
    try {
        @SuppressWarnings("unchecked")
        Map<String, Object> map = 
                (Map<String, Object>)new ObjectMapper().readValue(str, Map.class);
        language = map.containsKey("language") ? map.get("language").toString() : null ;
        data = map.containsKey("data") ? map.get("data").toString() : null ;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

the new ctor will be called by Jackson when you deserialize a Notification object:

Notification n = (Notification)new ObjectMapper().readValue(reader, Notification.class);
Find elsewhere
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 702023 โ€บ java โ€บ Include-Double-Quote-JSON-String
Include Double Quote in JSON String (Java in General forum at Coderanch)
Here is my connection code that save the string to the database: ... Steve Dyke wrote: A process within the app. It runs an SQL connection an creates the JSON. Here is the compiled string when the database filed is like \"A\" But on the printed placard I have like this "A""(an extra ") But what is that process taking in and what is it producing? Because it looks like it is not producing correct JSON. ... This: "NAME: DIVAN 2 PAX TYPE: ""A""" contains a couple of escaped double quotes.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ jsonobject-tostring-how-to-convert-json-to-a-string-in-java
JSONObject.toString() โ€“ How to Convert JSON to a String in Java
April 14, 2023 - In Java, the JSONObject class provided by the org.json package is commonly used to create and manipulate JSON objects. The JSONObject.toString() method is a useful method provided by this class that converts a JSON object to a string representation.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-convert-double-to-string
Java Convert double to String | DigitalOcean
August 3, 2022 - However java supports autoboxing, so they both can be used interchangeably in most of the cases. This is the easiest way to convert double to string in java.
๐ŸŒ
Java Guides
javaguides.net โ€บ 2018 โ€บ 08 โ€บ java-convert-double-to-string-example.html
Convert Double to String in Java
June 15, 2024 - In this article, we will show you how to convert Java double to String code examples. Performing conversion from wrapper class Double or primitive type double to String is a common scenario when programming with Core Java.
๐ŸŒ
Java67
java67.com โ€บ 2016 โ€บ 10 โ€บ 3-ways-to-convert-string-to-json-object-in-java.html
3 ways to convert String to JSON object in Java? Examples | Java67
Jackson is a very popular and efficient Java library to map Java objects to JSON and vice-versa. If you want to learn the basics of the Jackson library and how to use them, I suggest you take a look at the Jackson documentation. That's all about how to convert String to JSON objects in Java.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java numbers โ€บ convert double to string, removing decimal places
Convert Double to String, Removing Decimal Places | Baeldung
January 8, 2024 - In this tutorial, weโ€™ll take a look at the different ways to convert a double value to a String, removing its decimal places.
๐ŸŒ
Apps Developer Blog
appsdeveloperblog.com โ€บ home โ€บ java โ€บ java conversion โ€บ convert double to string in java
Convert Double to String in Java - Apps Developer Blog
March 21, 2023 - Converting double to String is a common task in Java programming. In many cases, you may need to convert a double value to a String to display it in a user interface, write it to a file, or pass it as an argument to a method that expects a String. Java provides several methods for converting a double to String, including String.valueOf(), Double.toString(), and formatting options.
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ tutorials โ€บ software & tech โ€บ convert double to string in java
Convert Double To String In Java
3 weeks ago - We'll explore how to prevent this and get a non-exponential string representation. Java Double to String without Decimal: Sometimes, we need to convert a double into a string but without any decimal places.
๐ŸŒ
NI Community
forums.ni.com โ€บ community โ€บ discussion forums โ€บ most active software boards โ€บ labview โ€บ json with type double number
Solved: json with type double number - NI Community
November 2, 2015 - Solved: How do I avoid the value conversion that occurs when flattening a type double number to JSON? a value of 9999.12 will convert to