/
SettableIntMethodProperty.java
73 lines (63 loc) · 2.26 KB
/
SettableIntMethodProperty.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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 SettableIntMethodProperty
extends OptimizedSettableBeanProperty<SettableIntMethodProperty>
{
private static final long serialVersionUID = 1L;
public SettableIntMethodProperty(SettableBeanProperty src,
BeanPropertyMutator mutator, int index)
{
super(src, mutator, index);
}
@Override
protected SettableBeanProperty withDelegate(SettableBeanProperty del) {
return new SettableIntMethodProperty(del, _propertyMutator, _optimizedIndex);
}
@Override
public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
return new SettableIntMethodProperty(delegate, mut, _optimizedIndex);
}
/*
/**********************************************************************
/* Deserialization
/**********************************************************************
*/
@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean) throws IOException
{
if (!p.isExpectedNumberIntToken()) {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
final int v = p.getIntValue();
try {
_propertyMutator.intSetter(bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(bean, v, e);
}
}
@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance)
throws IOException
{
if (p.isExpectedNumberIntToken()) {
return setAndReturn(instance, p.getIntValue());
}
return delegate.deserializeSetAndReturn(p, ctxt, instance);
}
@Override
public void set(Object bean, Object value) throws IOException {
// not optimal (due to boxing), but better than using reflection:
int v = ((Number) value).intValue();
try {
_propertyMutator.intSetter(bean, _optimizedIndex, v);
} catch (Throwable e) {
_reportProblem(bean, v, e);
}
}
}