Skip to content

Commit

Permalink
Fixed #120 (last pieces)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Dec 18, 2020
1 parent 4a1ea8a commit 645aa27
Show file tree
Hide file tree
Showing 29 changed files with 203 additions and 1,111 deletions.

Large diffs are not rendered by default.

Expand Up @@ -42,7 +42,8 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
} else if (t == JsonToken.VALUE_FALSE) {
b = false;
} else {
b = _deserializeBoolean(p, ctxt);
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
try {
_propertyMutator.booleanField(bean, _optimizedIndex, b);
Expand All @@ -66,15 +67,13 @@ public void set(Object bean, Object value) throws IOException {
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
boolean b;
JsonToken t = p.getCurrentToken();
JsonToken t = p.currentToken();
if (t == JsonToken.VALUE_TRUE) {
b = true;
} else if (t == JsonToken.VALUE_FALSE) {
b = false;
} else {
b = _deserializeBoolean(p, ctxt);
return setAndReturn(instance, Boolean.TRUE);
}
if (t == JsonToken.VALUE_FALSE) {
return setAndReturn(instance, Boolean.FALSE);
}
return setAndReturn(instance, b);
return delegate.deserializeSetAndReturn(p, ctxt, instance);
}
}
Expand Up @@ -42,7 +42,8 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
} else if (t == JsonToken.VALUE_FALSE) {
b = false;
} else {
b = _deserializeBoolean(p, ctxt);
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
try {
_propertyMutator.booleanSetter(bean, _optimizedIndex, b);
Expand All @@ -66,15 +67,13 @@ public void set(Object bean, Object value) throws IOException {
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
boolean b;
JsonToken t = p.getCurrentToken();
JsonToken t = p.currentToken();
if (t == JsonToken.VALUE_TRUE) {
b = true;
} else if (t == JsonToken.VALUE_FALSE) {
b = false;
} else {
b = _deserializeBoolean(p, ctxt);
return setAndReturn(instance, Boolean.TRUE);
}
if (t == JsonToken.VALUE_FALSE) {
return setAndReturn(instance, Boolean.FALSE);
}
return setAndReturn(instance, b);
return delegate.deserializeSetAndReturn(p, ctxt, instance);
}
}
Expand Up @@ -37,14 +37,28 @@ public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean) throws IOException
{
int v = p.isExpectedNumberIntToken() ? p.getIntValue() : _deserializeInt(p, ctxt);
if (!p.isExpectedNumberIntToken()) {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
final int v = p.getIntValue();
try {
_propertyMutator.intField(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:
Expand All @@ -55,12 +69,4 @@ public void set(Object bean, Object value) throws IOException {
_reportProblem(bean, v, e);
}
}

@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
int v = p.isExpectedNumberIntToken() ? p.getIntValue() : _deserializeInt(p, ctxt);
return setAndReturn(instance, v);
}
}
Expand Up @@ -37,15 +37,29 @@ public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean) throws IOException
{
int v = p.isExpectedNumberIntToken() ? p.getIntValue() : _deserializeInt(p, ctxt);
if (!p.isExpectedNumberIntToken()) {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
final int v = p.getIntValue();
try {
_propertyMutator.intSetter(bean, _optimizedIndex, v);
return;
} 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:
Expand All @@ -56,13 +70,4 @@ public void set(Object bean, Object value) throws IOException {
_reportProblem(bean, v, e);
}
}

@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance)
throws IOException
{
int v = p.isExpectedNumberIntToken() ? p.getIntValue() : _deserializeInt(p, ctxt);
return setAndReturn(instance, v);
}
}
Expand Up @@ -37,14 +37,28 @@ public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean) throws IOException
{
long v = p.isExpectedNumberIntToken() ? p.getLongValue() : _deserializeLong(p, ctxt);
if (!p.isExpectedNumberIntToken()) {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
final long v = p.getLongValue();
try {
_propertyMutator.longField(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.getLongValue());
}
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:
Expand All @@ -55,12 +69,4 @@ public void set(Object bean, Object value) throws IOException {
_reportProblem(bean, v, e);
}
}

@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
long l = p.isExpectedNumberIntToken() ? p.getLongValue() : _deserializeLong(p, ctxt);
return setAndReturn(instance, l);
}
}
Expand Up @@ -37,14 +37,28 @@ public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean) throws IOException
{
long v = p.isExpectedNumberIntToken() ? p.getLongValue() : _deserializeLong(p, ctxt);
if (!p.isExpectedNumberIntToken()) {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
final long v = p.getLongValue();
try {
_propertyMutator.longSetter(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.getLongValue());
}
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:
Expand All @@ -55,12 +69,4 @@ public void set(Object bean, Object value) throws IOException {
_reportProblem(bean, v, e);
}
}

@Override
public Object deserializeSetAndReturn(JsonParser p,
DeserializationContext ctxt, Object instance) throws IOException
{
long l = p.isExpectedNumberIntToken() ? p.getLongValue() : _deserializeLong(p, ctxt);
return setAndReturn(instance, l);
}
}
Expand Up @@ -37,21 +37,11 @@ public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
Object bean) throws IOException
{
String text;

if (p.hasToken(JsonToken.VALUE_STRING)) {
text = p.getText();
} else if (p.hasToken(JsonToken.VALUE_NULL)) {
if (_skipNulls) {
return;
}
text = (String) _nullProvider.getNullValue(ctxt);
} else {
text = p.getValueAsString();
if (text == null) {
text = _deserializeString(p, ctxt);
}
if (!p.hasToken(JsonToken.VALUE_STRING)) {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
final String text = p.getText();
try {
_propertyMutator.stringField(bean, _optimizedIndex, text);
} catch (Throwable e) {
Expand All @@ -63,22 +53,10 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt,
public Object deserializeSetAndReturn(JsonParser p, DeserializationContext ctxt, Object instance)
throws IOException
{
String text;

if (p.hasToken(JsonToken.VALUE_STRING)) {
text = p.getText();
} else if (p.hasToken(JsonToken.VALUE_NULL)) {
if (_skipNulls) {
return instance;
}
text = (String) _nullProvider.getNullValue(ctxt);
} else {
text = p.getValueAsString();
if (text == null) {
text = _deserializeString(p, ctxt);
}
return setAndReturn(instance, p.getText());
}
return setAndReturn(instance, text);
return delegate.deserializeSetAndReturn(p, ctxt, instance);
}

@Override
Expand Down
Expand Up @@ -37,21 +37,11 @@ public SettableBeanProperty withMutator(BeanPropertyMutator mut) {
@Override
public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object bean) throws IOException
{
String text;

if (p.hasToken(JsonToken.VALUE_STRING)) {
text = p.getText();
} else if (p.hasToken(JsonToken.VALUE_NULL)) {
if (_skipNulls) {
return;
}
text = (String) _nullProvider.getNullValue(ctxt);
} else {
text = p.getValueAsString();
if (text == null) {
text = _deserializeString(p, ctxt);
}
if (!p.hasToken(JsonToken.VALUE_STRING)) {
delegate.deserializeAndSet(p, ctxt, bean);
return;
}
final String text = p.getText();
try {
_propertyMutator.stringSetter(bean, _optimizedIndex, text);
} catch (Throwable e) {
Expand All @@ -62,22 +52,10 @@ public void deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object
@Override
public Object deserializeSetAndReturn(JsonParser p, DeserializationContext ctxt, Object instance) throws IOException
{
String text;

if (p.hasToken(JsonToken.VALUE_STRING)) {
text = p.getText();
} else if (p.hasToken(JsonToken.VALUE_NULL)) {
if (_skipNulls) {
return instance;
}
text = (String) _nullProvider.getNullValue(ctxt);
} else {
text = p.getValueAsString();
if (text == null) {
text = _deserializeString(p, ctxt);
}
return setAndReturn(instance, p.getText());
}
return setAndReturn(instance, text);
return delegate.deserializeSetAndReturn(p, ctxt, instance);
}

@Override
Expand Down
Expand Up @@ -40,13 +40,14 @@ public Organization(@JsonProperty("id") long id,
/**********************************************************
*/

private final ObjectMapper MAPPER = newAfterburnerMapper();

public void testFinalFields() throws Exception
{
ObjectMapper mapper = objectMapper();
String json = mapper.writeValueAsString(new Organization[] {
String json = MAPPER.writeValueAsString(new Organization[] {
new Organization(123L, "Corp", new Address(98040, 98021))
});
Organization[] result = mapper.readValue(json, Organization[].class);
Organization[] result = MAPPER.readValue(json, Organization[].class);
assertNotNull(result);
assertEquals(1, result.length);
assertNotNull(result[0]);
Expand All @@ -60,11 +61,10 @@ public void testFinalFields42() throws Exception
{
JsonAddress address = new JsonAddress(-1L, "line1", "line2", "city", "state", "zip", "locale", "timezone");
JsonOrganization organization = new JsonOrganization(-1L, "name", address);
ObjectMapper mapper = objectMapper();
String json = mapper.writeValueAsString(organization);
String json = MAPPER.writeValueAsString(organization);
assertNotNull(json);

JsonOrganization result = mapper.readValue(json, JsonOrganization.class);
JsonOrganization result = MAPPER.readValue(json, JsonOrganization.class);
assertNotNull(result);
}

Expand Down
Expand Up @@ -51,19 +51,22 @@ public void testFailPrimitiveFromNull() throws Exception
FAIL_ON_NULL_MAPPER.readValue(BEAN_WITH_NULL_VALUE, IntBean.class);
fail();
} catch (MismatchedInputException e) {
verifyException(e, "Cannot coerce `null` to `int` value");
// verifyException(e, "Cannot coerce `null` to `int` value");
verifyException(e, "Cannot map `null` into type int");
}
try {
FAIL_ON_NULL_MAPPER.readValue(BEAN_WITH_NULL_VALUE, LongBean.class);
fail();
} catch (MismatchedInputException e) {
verifyException(e, "Cannot coerce `null` to `long` value");
// verifyException(e, "Cannot coerce `null` to `long` value");
verifyException(e, "Cannot map `null` into type long");
}
try {
FAIL_ON_NULL_MAPPER.readValue(BEAN_WITH_NULL_VALUE, BooleanBean.class);
fail();
} catch (MismatchedInputException e) {
verifyException(e, "Cannot coerce `null` to `boolean` value");
// verifyException(e, "Cannot coerce `null` to `boolean` value");
verifyException(e, "Cannot map `null` into type boolean");
}
try {
FAIL_ON_NULL_MAPPER.readValue(BEAN_WITH_NULL_VALUE, DoubleBean.class);
Expand Down

0 comments on commit 645aa27

Please sign in to comment.