Skip to content

Commit

Permalink
Merge branch '2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 16, 2024
2 parents e9cf682 + 1781de7 commit be3c753
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public void writeProperty(String propName, Object value, int type) throws Jackso
// Scalar types:

case SER_BOOLEAN:
case SER_BOOLEAN_WRAPPER:
writeBooleanProperty(propName, ((Boolean) value).booleanValue());
return;
case SER_CHAR:
Expand Down Expand Up @@ -353,6 +354,7 @@ protected void _writeValue(Object value, int type) throws JacksonException
// Other scalar types:

case SER_BOOLEAN:
case SER_BOOLEAN_WRAPPER:
writeBooleanValue(((Boolean) value).booleanValue());
return;
case SER_CHAR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public Object readNext(JSONReader reader, JsonParser p) throws JacksonException
// Other scalar types:

case SER_BOOLEAN:
case SER_BOOLEAN_WRAPPER:
{
Boolean b = p.nextBooleanValue();
if (b != null) {
Expand Down Expand Up @@ -138,14 +139,16 @@ public Object read(JSONReader reader, JsonParser p) throws JacksonException
// Other scalar types:

case SER_BOOLEAN:
case SER_BOOLEAN_WRAPPER:
switch (p.currentTokenId()) {
case JsonTokenId.ID_TRUE:
return Boolean.TRUE;
case JsonTokenId.ID_FALSE:
return Boolean.FALSE;
case JsonTokenId.ID_NULL:
// 07-Jul-2020, tatu: since `boolean` and `java.lang.Boolean` both handled
// here, can not (alas!) separate yet
if (_typeId == SER_BOOLEAN_WRAPPER) {
return null;
}
return Boolean.FALSE;

case JsonTokenId.ID_STRING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,27 @@ public abstract class ValueLocatorBase
// // // Other specific scalar types

public final static int SER_BOOLEAN = 22;
public final static int SER_CHAR = 23;
public final static int SER_BOOLEAN_WRAPPER = 23;
public final static int SER_CHAR = 24;

public final static int SER_ENUM = 24;
public final static int SER_ENUM = 25;

public final static int SER_DATE = 25;
public final static int SER_CALENDAR = 26;
public final static int SER_DATE = 26;
public final static int SER_CALENDAR = 27;

public final static int SER_CLASS = 27;
public final static int SER_FILE = 28;
public final static int SER_UUID = 29;
public final static int SER_URL = 30;
public final static int SER_URI = 31;
public final static int SER_CLASS = 28;
public final static int SER_FILE = 29;
public final static int SER_UUID = 30;
public final static int SER_URL = 31;
public final static int SER_URI = 32;

// // // Iterate-able types

/**
* Anything that implements {@link java.lang.Iterable}, but not
* {@link java.util.Collection}.
*/
public final static int SER_ITERABLE = 32;
public final static int SER_ITERABLE = 33;

/*
/**********************************************************************
Expand Down Expand Up @@ -174,7 +175,7 @@ protected int _findSimpleType(Class<?> raw, boolean forSer)
throw new IllegalArgumentException("Unrecognized primitive type: "+raw.getName());
}
if (raw == Boolean.class) {
return SER_BOOLEAN;
return SER_BOOLEAN_WRAPPER;
}
if (Number.class.isAssignableFrom(raw)) {
if (raw == Integer.class) return SER_NUMBER_INTEGER;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package tools.jackson.jr.failing;

import java.util.LinkedHashMap;
import java.util.Map;

import tools.jackson.jr.ob.JSON;
import tools.jackson.jr.ob.TestBase;

Expand All @@ -21,32 +18,13 @@ static class LongWrapper {
static class LongPrimitiveWrapper {
public long value;
}
static class BooleanWrapper {
public Boolean value;
}
static class BooleanPrimitiveWrapper {
public boolean value;
}
static class DoubleWrapper {
public Double value;
}
static class DoublePrimitiveWrapper {
public double value;
}

// Test to verify that outputting of nulls is configurable
public void testMapNullEntries() throws Exception
{
Map<String,Object> map = new LinkedHashMap<String,Object>();
map.put("a", 1);
map.put("b", null);
// By default we do NOT write null-valued entries:
assertEquals("{\"a\":1}", JSON.std.asString(map));
// but we can disable it easily
assertEquals("{\"a\":1,\"b\":null}",
JSON.std.with(JSON.Feature.WRITE_NULL_PROPERTIES).asString(map));
}

// [jackson-jr#78], int/Integer

public void testIntPrimitive() throws Exception
Expand Down Expand Up @@ -97,30 +75,6 @@ public void testLongWrapper() throws Exception

// [jackson-jr#78], boolean/Boolean

public void testBooleanPrimitive() throws Exception
{
BooleanPrimitiveWrapper w = JSON.std.beanFrom(BooleanPrimitiveWrapper.class,
a2q("{'value':true}"));
assertTrue(w.value);

w = JSON.std.beanFrom(BooleanPrimitiveWrapper.class,
a2q("{'value':null}"));
assertFalse(w.value);
}

public void testBooleanWrapper() throws Exception
{
BooleanWrapper w = JSON.std.beanFrom(BooleanWrapper.class,
a2q("{'value':true}"));
assertEquals(Boolean.TRUE, w.value);

w = JSON.std.beanFrom(BooleanWrapper.class,
a2q("{'value':null}"));
assertNull(w.value);
}

// [jackson-jr#78], boolean/Boolean

public void testDoublePrimitive() throws Exception
{
DoublePrimitiveWrapper w = JSON.std.beanFrom(DoublePrimitiveWrapper.class,
Expand Down
32 changes: 32 additions & 0 deletions jr-objects/src/test/java/tools/jackson/jr/ob/NullHandlingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ static class StringBean {
public String str = "a";
}

static class BooleanWrapper {
public Boolean value;
}
static class BooleanPrimitiveWrapper {
public boolean value;
}

// Test to verify that outputting of nulls is configurable
public void testMapNullEntries() throws Exception
{
Expand Down Expand Up @@ -42,4 +49,29 @@ public void testNullForByteArray() throws Exception
Bean107 bean = JSON.std.beanFrom(Bean107.class, a2q("{'b':null}"));
assertNull(bean.b);
}

// [jackson-jr#78], boolean/Boolean

public void testBooleanPrimitive() throws Exception
{
BooleanPrimitiveWrapper w = JSON.std.beanFrom(BooleanPrimitiveWrapper.class,
a2q("{'value':true}"));
assertTrue(w.value);

w = JSON.std.beanFrom(BooleanPrimitiveWrapper.class,
a2q("{'value':null}"));
assertFalse(w.value);
}

public void testBooleanWrapper() throws Exception
{
BooleanWrapper w = JSON.std.beanFrom(BooleanWrapper.class,
a2q("{'value':true}"));
assertEquals(Boolean.TRUE, w.value);

w = JSON.std.beanFrom(BooleanWrapper.class,
a2q("{'value':null}"));
assertNull(w.value);
}

}

0 comments on commit be3c753

Please sign in to comment.