Java AtomicIntegerDeserializer-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.AtomicInteger;
public class AtomicIntegerDeserializer extends StdScalarDeserializer<AtomicInteger> {
public AtomicIntegerDeserializer() {
super(AtomicInteger.class);
}
@Override
public AtomicInteger deserialize(JsonParser parser, DeserializationContext context) throws IOException {
return new AtomicInteger(parser.getValueAsInt());
}
}
This is a simple example of a custom deserializer for the AtomicInteger class in Jackson. This class extends StdScalarDeserializer and overrides the deserialize method to handle converting a JSON value to an AtomicInteger instance.