Java DecimalNode-class And Method Code Example


Here is an example of using the DecimalNode class in the com.fasterxml.jackson.databind package in Java:

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.DecimalNode;
import java.math.BigDecimal;

public class Example {
    public static void main(String[] args) throws Exception {
        BigDecimal decimalValue = new BigDecimal("123456789123456789123456789.123456789123456789123456789");
        JsonNode decimalNode = DecimalNode.valueOf(decimalValue);
        System.out.println(decimalNode);
    }
}

This example creates an instance of the BigDecimal class, which is a decimal number with arbitrary precision. It also creates an instance of the DecimalNode class by calling valueOf method. With this, you can use the DecimalNode to represent decimal numbers in JSON.

In this example, the valueOf method is used to create a DecimalNode object that wraps the BigDecimal object.

This example prints the DecimalNode as a json string to the console.