Java AtomicLongDeserializer-class And Method Code Example


import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicLong;

public class AtomicLongDeserializer extends StdScalarDeserializer<AtomicLong> {
    public AtomicLongDeserializer() {
        super(AtomicLong.class);
    }

    @Override
    public AtomicLong deserialize(JsonParser parser, DeserializationContext context) throws IOException {
        return new AtomicLong(parser.getValueAsLong());
    }
}

This is a simple example of a custom deserializer for the AtomicLong class in Jackson. This class extends StdScalarDeserializer and overrides the deserialize method to handle converting a JSON value to an AtomicLong instance.

It is similar to AtomicIntegerDeserializer but it uses getValueAsLong() instead of getValueAsInt() to deserialize the value from json.