com.fasterxml.jackson.module.afterburner.deser.SettableBooleanFieldProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jackson-module-afterburner Show documentation
Show all versions of jackson-module-afterburner Show documentation
Jackson (https://github.com/FasterXML/jackson) extension module
used to enhance performance using bytecode generation to replace use of Reflection for
field access and method calls
package com.fasterxml.jackson.module.afterburner.deser;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
public final class SettableBooleanFieldProperty
extends OptimizedSettableBeanProperty
{
private static final long serialVersionUID = 1L;
public SettableBooleanFieldProperty(SettableBeanProperty src,
BeanPropertyMutator mutator, int index)
{
super(src, mutator, index);
}
@Override
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
return new SettableBooleanFieldProperty(del, _propertyMutator, _optimizedIndex);
}
@Override
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
return new SettableBooleanFieldProperty(delegate, mut, _optimizedIndex);
}
/*
/**********************************************************************
/* Deserialization
/**********************************************************************
*/
@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object bean) throws IOException {
boolean b;
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_TRUE) {
b = true;
} else if (t == JsonToken.VALUE_FALSE) {
b = false;
} else {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
try {
_propertyMutator.booleanField(bean, _optimizedIndex, b);
} catch (Throwable e) {
_reportProblem(bean, b, e);
}
}
@Override
public void set(Object bean, Object value) throws IOException {
// not optimal (due to boxing), but better than using reflection:
final boolean b = ((Boolean) value).booleanValue();
try {
_propertyMutator.booleanField(bean, _optimizedIndex, b);
} catch (Throwable e) {
_reportProblem(bean, b, e);
}
}
@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
JsonToken t = p.currentToken();
if (t == JsonToken.VALUE_TRUE) {
return setAndReturn(instance, Boolean.TRUE);
}
if (t == JsonToken.VALUE_FALSE) {
return setAndReturn(instance, Boolean.FALSE);
}
return delegate.deserializeSetAndReturn(p, ctxt, instance);
}
}