diff options
author | Tatu Saloranta <tatu.saloranta@iki.fi> | 2016-10-21 16:04:18 -0700 |
---|---|---|
committer | Tatu Saloranta <tatu.saloranta@iki.fi> | 2016-10-21 16:04:18 -0700 |
commit | db974ebbde10074125351adcde96374390bc9581 (patch) | |
tree | bca5528c5d35c57dccca43c2d388fe81babe8c50 | |
parent | 59a79720e4569887fb7c38501dd6bfcc5d89bb5d (diff) | |
download | jackson-databind-db974ebbde10074125351adcde96374390bc9581.tar.gz |
more test coverage improvements
7 files changed, 307 insertions, 109 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 118a82b3a..2ca537de3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -320,7 +320,7 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); } } else if (rootName.isEmpty()) { wrap = false; - } else { // [JACKSON-764] + } else { // empty String means explicitly disabled; non-empty that it is enabled wrap = true; gen.writeStartObject(); @@ -331,14 +331,8 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); if (wrap) { gen.writeEndObject(); } - } catch (IOException ioe) { // As per [JACKSON-99], pass IOException and subtypes as-is - throw ioe; - } catch (Exception e) { // but wrap RuntimeExceptions, to get path information - String msg = e.getMessage(); - if (msg == null) { - msg = "[no message for "+e.getClass().getName()+"]"; - } - throw new JsonMappingException(gen, msg, e); + } catch (Exception e) { + throw _wrapAsIOE(gen, e); } } @@ -353,6 +347,8 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); * @param rootType Type to use for locating serializer to use, instead of actual * runtime type. Must be actual type, or one of its super types */ + // 21-Oct-2016, tatu: Does not seem to be used.... remove for 2.9? + /* public void serializeValue(JsonGenerator gen, Object value, JavaType rootType) throws IOException { _generator = gen; @@ -390,16 +386,11 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); if (wrap) { gen.writeEndObject(); } - } catch (IOException ioe) { // no wrapping for IO (and derived) - throw ioe; - } catch (Exception e) { // but others do need to be, to get path etc - String msg = e.getMessage(); - if (msg == null) { - msg = "[no message for "+e.getClass().getName()+"]"; - } - reportMappingProblem(e, msg); + } catch (Exception e) { + throw _wrapAsIOE(gen, e); } } + */ /** * The method to be called by {@link ObjectWriter} @@ -444,7 +435,7 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); } } else if (rootName.isEmpty()) { wrap = false; - } else { // [JACKSON-764] + } else { // empty String means explicitly disabled; non-empty that it is enabled wrap = true; gen.writeStartObject(); @@ -455,14 +446,8 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); if (wrap) { gen.writeEndObject(); } - } catch (IOException ioe) { // no wrapping for IO (and derived) - throw ioe; - } catch (Exception e) { // but others do need to be, to get path etc - String msg = e.getMessage(); - if (msg == null) { - msg = "[no message for "+e.getClass().getName()+"]"; - } - reportMappingProblem(e, msg); + } catch (Exception e) { + throw _wrapAsIOE(gen, e); } } @@ -519,29 +504,12 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); if (wrap) { gen.writeEndObject(); } - } catch (IOException ioe) { // no wrapping for IO (and derived) - throw ioe; - } catch (Exception e) { // but others do need to be, to get path etc - String msg = e.getMessage(); - if (msg == null) { - msg = "[no message for "+e.getClass().getName()+"]"; - } - reportMappingProblem(e, msg); + } catch (Exception e) { + throw _wrapAsIOE(gen, e); } } /** - * @deprecated since 2.6; remove from 2.7 or later - */ - @Deprecated - public void serializePolymorphic(JsonGenerator gen, Object value, TypeSerializer typeSer) - throws IOException - { - JavaType t = (value == null) ? null : _config.constructType(value.getClass()); - serializePolymorphic(gen, value, t, null, typeSer); - } - - /** * Helper method called when root value to serialize is null * * @since 2.3 @@ -551,16 +519,22 @@ filter.getClass().getName(), t.getClass().getName(), t.getMessage()); JsonSerializer<Object> ser = getDefaultNullValueSerializer(); try { ser.serialize(null, gen, this); - } catch (IOException ioe) { // no wrapping for IO (and derived) - throw ioe; - } catch (Exception e) { // but others do need to be, to get path etc - String msg = e.getMessage(); - if (msg == null) { - msg = "[no message for "+e.getClass().getName()+"]"; - } - reportMappingProblem(e, msg); + } catch (Exception e) { + throw _wrapAsIOE(gen, e); } } + + private IOException _wrapAsIOE(JsonGenerator g, Exception e) { + if (e instanceof IOException) { + return (IOException) e; + } + String msg = e.getMessage(); + if (msg == null) { + msg = "[no message for "+e.getClass().getName()+"]"; + } + return new JsonMappingException(g, msg, e); + } + /* /******************************************************** /* Access to caching details diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index d7539b2b1..065a3be4e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -28,7 +28,7 @@ public class TokenBufferSerializer @Override public void serialize(TokenBuffer value, JsonGenerator jgen, SerializerProvider provider) - throws IOException + throws IOException { value.serialize(jgen); } diff --git a/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java b/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java index 67d63ed26..9a7e98b85 100644 --- a/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java +++ b/src/main/java/com/fasterxml/jackson/databind/util/BeanUtil.java @@ -79,6 +79,7 @@ public class BeanUtil /** * @since 2.5 */ + @Deprecated // since 2.9, not used any more public static String okNameForSetter(AnnotatedMethod am, boolean stdNaming) { String name = okNameForMutator(am, "set", stdNaming); if ((name != null) @@ -161,25 +162,21 @@ public class BeanUtil { Class<?> rt = am.getRawType(); // Ok, first: must return an array type - if (rt == null || !rt.isArray()) { - return false; - } - /* And that type needs to be "net.sf.cglib.proxy.Callback". - * Theoretically could just be a type that implements it, but - * for now let's keep things simple, fix if need be. - */ - Class<?> compType = rt.getComponentType(); - // Actually, let's just verify it's a "net.sf.cglib.*" class/interface - String pkgName = ClassUtil.getPackageName(compType); - if (pkgName != null) { - if (pkgName.contains(".cglib")) { - if (pkgName.startsWith("net.sf.cglib") - // also, as per [JACKSON-177] - || pkgName.startsWith("org.hibernate.repackage.cglib") - // and [core#674] - || pkgName.startsWith("org.springframework.cglib") - ) { - return true; + if (rt.isArray()) { + /* And that type needs to be "net.sf.cglib.proxy.Callback". + * Theoretically could just be a type that implements it, but + * for now let's keep things simple, fix if need be. + */ + Class<?> compType = rt.getComponentType(); + // Actually, let's just verify it's a "net.sf.cglib.*" class/interface + String pkgName = ClassUtil.getPackageName(compType); + if (pkgName != null) { + if (pkgName.contains(".cglib")) { + return pkgName.startsWith("net.sf.cglib") + // also, as per [JACKSON-177] + || pkgName.startsWith("org.hibernate.repackage.cglib") + // and [core#674] + || pkgName.startsWith("org.springframework.cglib"); } } } @@ -194,10 +191,7 @@ public class BeanUtil { Class<?> argType = am.getRawParameterType(0); String pkgName = ClassUtil.getPackageName(argType); - if (pkgName != null && pkgName.startsWith("groovy.lang")) { - return true; - } - return false; + return (pkgName != null) && pkgName.startsWith("groovy.lang"); } /** @@ -205,15 +199,8 @@ public class BeanUtil */ protected static boolean isGroovyMetaClassGetter(AnnotatedMethod am) { - Class<?> rt = am.getRawType(); - if (rt == null || rt.isArray()) { - return false; - } - String pkgName = ClassUtil.getPackageName(rt); - if (pkgName != null && pkgName.startsWith("groovy.lang")) { - return true; - } - return false; + String pkgName = ClassUtil.getPackageName(am.getRawType()); + return (pkgName != null) && pkgName.startsWith("groovy.lang"); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/util/TokenBuffer.java b/src/main/java/com/fasterxml/jackson/databind/util/TokenBuffer.java index 58d15fc99..6e3c44734 100644 --- a/src/main/java/com/fasterxml/jackson/databind/util/TokenBuffer.java +++ b/src/main/java/com/fasterxml/jackson/databind/util/TokenBuffer.java @@ -1157,7 +1157,9 @@ sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(","); _appendAt = 1; } } - + + // 21-Oct-2016, tatu: Does not seem to be used or needed + /* protected final void _appendRaw(int rawType, Object value) { Segment next = _hasNativeId @@ -1170,6 +1172,7 @@ sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(","); _appendAt = 1; } } + */ @Override protected void _reportUnsupportedOperation() { @@ -1795,6 +1798,7 @@ sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(","); return _next; } + /* public Segment appendRaw(int index, int rawTokenType, Object value) { if (index < TOKENS_PER_SEGMENT) { @@ -1818,32 +1822,33 @@ sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(","); return _next; } - private void set(int index, JsonToken tokenType) + private void set(int index, int rawTokenType, Object value, Object objectId, Object typeId) { - /* Assumption here is that there are no overwrites, just appends; - * and so no masking is needed (nor explicit setting of null) - */ - long typeCode = tokenType.ordinal(); + _tokens[index] = value; + long typeCode = (long) rawTokenType; if (index > 0) { typeCode <<= (index << 2); } _tokenTypes |= typeCode; + assignNativeIds(index, objectId, typeId); } - private void set(int index, JsonToken tokenType, - Object objectId, Object typeId) + private void set(int index, int rawTokenType, Object value) { - long typeCode = tokenType.ordinal(); + _tokens[index] = value; + long typeCode = (long) rawTokenType; if (index > 0) { typeCode <<= (index << 2); } _tokenTypes |= typeCode; - assignNativeIds(index, objectId, typeId); } + */ - private void set(int index, JsonToken tokenType, Object value) + private void set(int index, JsonToken tokenType) { - _tokens[index] = value; + /* Assumption here is that there are no overwrites, just appends; + * and so no masking is needed (nor explicit setting of null) + */ long typeCode = tokenType.ordinal(); if (index > 0) { typeCode <<= (index << 2); @@ -1851,10 +1856,9 @@ sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(","); _tokenTypes |= typeCode; } - private void set(int index, JsonToken tokenType, Object value, + private void set(int index, JsonToken tokenType, Object objectId, Object typeId) { - _tokens[index] = value; long typeCode = tokenType.ordinal(); if (index > 0) { typeCode <<= (index << 2); @@ -1863,20 +1867,21 @@ sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(","); assignNativeIds(index, objectId, typeId); } - private void set(int index, int rawTokenType, Object value) + private void set(int index, JsonToken tokenType, Object value) { _tokens[index] = value; - long typeCode = (long) rawTokenType; + long typeCode = tokenType.ordinal(); if (index > 0) { typeCode <<= (index << 2); } _tokenTypes |= typeCode; } - private void set(int index, int rawTokenType, Object value, Object objectId, Object typeId) + private void set(int index, JsonToken tokenType, Object value, + Object objectId, Object typeId) { _tokens[index] = value; - long typeCode = (long) rawTokenType; + long typeCode = tokenType.ordinal(); if (index > 0) { typeCode <<= (index << 2); } @@ -1900,14 +1905,14 @@ sb.append("NativeObjectIds=").append(_hasNativeObjectIds).append(","); /** * @since 2.3 */ - public Object findObjectId(int index) { + private Object findObjectId(int index) { return (_nativeIds == null) ? null : _nativeIds.get(_objectIdIndex(index)); } /** * @since 2.3 */ - public Object findTypeId(int index) { + private Object findTypeId(int index) { return (_nativeIds == null) ? null : _nativeIds.get(_typeIdIndex(index)); } diff --git a/src/test/java/com/fasterxml/jackson/databind/format/MapEntryFormatTest.java b/src/test/java/com/fasterxml/jackson/databind/format/MapEntryFormatTest.java index 7540ba49a..477359cfc 100644 --- a/src/test/java/com/fasterxml/jackson/databind/format/MapEntryFormatTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/format/MapEntryFormatTest.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.format; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonInclude; @@ -60,6 +61,30 @@ public class MapEntryFormatTest extends BaseMapTest } } + static class EntryWithDefaultWrapper { + @JsonInclude(value=JsonInclude.Include.NON_EMPTY, + content=JsonInclude.Include.NON_DEFAULT) + public Map.Entry<String,String> entry; + + public EntryWithDefaultWrapper(String key, String value) { + HashMap<String,String> map = new HashMap<>(); + map.put(key, value); + entry = map.entrySet().iterator().next(); + } + } + + static class EntryWithNonAbsentWrapper { + @JsonInclude(value=JsonInclude.Include.NON_EMPTY, + content=JsonInclude.Include.NON_ABSENT) + public Map.Entry<String,AtomicReference<String>> entry; + + public EntryWithNonAbsentWrapper(String key, String value) { + HashMap<String,AtomicReference<String>> map = new HashMap<>(); + map.put(key, new AtomicReference<String>(value)); + entry = map.entrySet().iterator().next(); + } + } + static class EmptyEntryWrapper { @JsonInclude(value=JsonInclude.Include.NON_EMPTY, content=JsonInclude.Include.NON_EMPTY) @@ -109,13 +134,29 @@ public class MapEntryFormatTest extends BaseMapTest assertEquals(aposToQuotes("{'entry':{'a':'b'}}"), MAPPER.writeValueAsString(new EmptyEntryWrapper("a", "b"))); assertEquals(aposToQuotes("{'entry':{'a':'b'}}"), + MAPPER.writeValueAsString(new EntryWithDefaultWrapper("a", "b"))); + assertEquals(aposToQuotes("{'entry':{'a':'b'}}"), MAPPER.writeValueAsString(new EntryWithNullWrapper("a", "b"))); assertEquals(aposToQuotes("{}"), MAPPER.writeValueAsString(new EmptyEntryWrapper("a", ""))); + assertEquals(aposToQuotes("{}"), + MAPPER.writeValueAsString(new EntryWithDefaultWrapper("a", ""))); assertEquals(aposToQuotes("{'entry':{'a':''}}"), MAPPER.writeValueAsString(new EntryWithNullWrapper("a", ""))); assertEquals(aposToQuotes("{}"), MAPPER.writeValueAsString(new EntryWithNullWrapper("a", null))); } + + public void testInclusionWithReference() throws Exception + { + assertEquals(aposToQuotes("{'entry':{'a':'b'}}"), + MAPPER.writeValueAsString(new EntryWithNonAbsentWrapper("a", "b"))); + // empty String not excluded since reference is not absent, just points to empty + // (so would need 3rd level inclusion definition) + assertEquals(aposToQuotes("{'entry':{'a':''}}"), + MAPPER.writeValueAsString(new EntryWithNonAbsentWrapper("a", ""))); + assertEquals(aposToQuotes("{}"), + MAPPER.writeValueAsString(new EntryWithNonAbsentWrapper("a", null))); + } } diff --git a/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java b/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java index 4246be230..afd173292 100644 --- a/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/util/BeanUtilTest.java @@ -1,9 +1,40 @@ package com.fasterxml.jackson.databind.util; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; + +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.BaseMapTest; +import com.fasterxml.jackson.databind.introspect.AnnotatedMethod; +import com.fasterxml.jackson.databind.type.TypeFactory; public class BeanUtilTest extends BaseMapTest { + static class IsGetters { + public boolean isPrimitive() { return false; } + public Boolean isWrapper() { return false; } + public String isNotGetter() { return null; } + public boolean is() { return false; } + } + + static class Getters { + public String getCallbacks() { return null; } + public String getMetaClass() { return null; } + public boolean get() { return false; } + } + + static class Setters { + public void setFoo() { } + public void notSetter() { } + public void set() { } + } + + /* + /********************************************************** + /* Test methods + /********************************************************** + */ + public void testNameMangle() { assertEquals("foo", BeanUtil.legacyManglePropertyName("getFoo", 3)); @@ -12,4 +43,105 @@ public class BeanUtilTest extends BaseMapTest assertEquals("url", BeanUtil.legacyManglePropertyName("getURL", 3)); assertEquals("URL", BeanUtil.stdManglePropertyName("getURL", 3)); } + + public void testGetDefaultValue() + { + TypeFactory tf = TypeFactory.defaultInstance(); + // For collection/array/Map types, should give `NOT_EMPTY`: + assertEquals(JsonInclude.Include.NON_EMPTY, + BeanUtil.getDefaultValue(tf.constructType(Map.class))); + assertEquals(JsonInclude.Include.NON_EMPTY, + BeanUtil.getDefaultValue(tf.constructType(List.class))); + assertEquals(JsonInclude.Include.NON_EMPTY, + BeanUtil.getDefaultValue(tf.constructType(Object[].class))); + // as well as ReferenceTypes, String + assertEquals(JsonInclude.Include.NON_EMPTY, + BeanUtil.getDefaultValue(tf.constructType(AtomicReference.class))); + assertEquals("", + BeanUtil.getDefaultValue(tf.constructType(String.class))); + // primitive/wrappers have others + assertEquals(Integer.valueOf(0), + BeanUtil.getDefaultValue(tf.constructType(Integer.class))); + + + // but POJOs have no real default + assertNull(BeanUtil.getDefaultValue(tf.constructType(getClass()))); + } + + public void testIsGetter() throws Exception + { + _testIsGetter("isPrimitive", "primitive"); + _testIsGetter("isWrapper", "wrapper"); + _testIsGetter("isNotGetter", null); + _testIsGetter("is", null); + } + + public void testOkNameForGetter() throws Exception + { + // mostly chosen to exercise groovy exclusion + _testOkNameForGetter("getCallbacks", "callbacks"); + _testOkNameForGetter("getMetaClass", "metaClass"); + _testOkNameForGetter("get", null); + } + + public void testOkNameForSetter() throws Exception + { + _testOkNameForSetter("setFoo", "foo"); + _testOkNameForSetter("notSetter", null); + _testOkNameForSetter("set", null); + } + + /* + /********************************************************** + /* Helper methods + /********************************************************** + */ + + private void _testIsGetter(String name, String expName) throws Exception { + _testIsGetter(name, expName, true); + _testIsGetter(name, expName, false); + } + + private void _testIsGetter(String name, String expName, boolean useStd) throws Exception + { + AnnotatedMethod m = _method(IsGetters.class, name); + if (expName == null) { + assertNull(BeanUtil.okNameForIsGetter(m, name, useStd)); + } else { + assertEquals(expName, BeanUtil.okNameForIsGetter(m, name, useStd)); + } + } + + private void _testOkNameForGetter(String name, String expName) throws Exception { + _testOkNameForGetter(name, expName, true); + _testOkNameForGetter(name, expName, false); + } + + private void _testOkNameForGetter(String name, String expName, boolean useStd) throws Exception { + AnnotatedMethod m = _method(Getters.class, name); + if (expName == null) { + assertNull(BeanUtil.okNameForGetter(m, useStd)); + } else { + assertEquals(expName, BeanUtil.okNameForGetter(m, useStd)); + } + } + + private void _testOkNameForSetter(String name, String expName) throws Exception { + _testOkNameForSetter(name, expName, true); + _testOkNameForSetter(name, expName, false); + } + + @SuppressWarnings("deprecation") + private void _testOkNameForSetter(String name, String expName, boolean useStd) throws Exception { + AnnotatedMethod m = _method(Setters.class, name); + if (expName == null) { + assertNull(BeanUtil.okNameForSetter(m, useStd)); + } else { + assertEquals(expName, BeanUtil.okNameForSetter(m, useStd)); + } + } + + private AnnotatedMethod _method(Class<?> cls, String name, Class<?>...parameterTypes) throws Exception { + return new AnnotatedMethod(null, cls.getMethod(name, parameterTypes), null, null); + } } diff --git a/src/test/java/com/fasterxml/jackson/databind/util/TestTokenBuffer.java b/src/test/java/com/fasterxml/jackson/databind/util/TestTokenBuffer.java index ed009af5b..5cf81e230 100644 --- a/src/test/java/com/fasterxml/jackson/databind/util/TestTokenBuffer.java +++ b/src/test/java/com/fasterxml/jackson/databind/util/TestTokenBuffer.java @@ -1,12 +1,15 @@ package com.fasterxml.jackson.databind.util; import java.io.*; +import java.math.BigDecimal; +import java.math.BigInteger; import java.util.UUID; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.io.SerializedString; import com.fasterxml.jackson.core.util.JsonParserSequence; -import com.fasterxml.jackson.databind.BaseMapTest; -import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.*; public class TestTokenBuffer extends BaseMapTest { @@ -18,13 +21,36 @@ public class TestTokenBuffer extends BaseMapTest /********************************************************** */ + public void testBasicConfig() throws IOException + { + TokenBuffer buf; + + buf = new TokenBuffer(MAPPER, false); + assertEquals(MAPPER.version(), buf.version()); + assertSame(MAPPER, buf.getCodec()); + assertNotNull(buf.getOutputContext()); + assertFalse(buf.isClosed()); + + buf.setCodec(null); + assertNull(buf.getCodec()); + + assertFalse(buf.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII)); + buf.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII); + assertTrue(buf.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII)); + buf.disable(JsonGenerator.Feature.ESCAPE_NON_ASCII); + assertFalse(buf.isEnabled(JsonGenerator.Feature.ESCAPE_NON_ASCII)); + + buf.close(); + assertTrue(buf.isClosed()); + } + /** * Test writing of individual simple values */ public void testSimpleWrites() throws IOException { TokenBuffer buf = new TokenBuffer(null, false); // no ObjectCodec - + // First, with empty buffer JsonParser p = buf.asParser(); assertNull(p.getCurrentToken()); @@ -387,6 +413,39 @@ public class TestTokenBuffer extends BaseMapTest buf.close(); } + public void testBasicSerialize() throws IOException + { + TokenBuffer buf; + + // let's see how empty works... + buf = new TokenBuffer(MAPPER, false); + assertEquals("", MAPPER.writeValueAsString(buf)); + buf.close(); + + buf = new TokenBuffer(MAPPER, false); + buf.writeStartArray(); + buf.writeBoolean(true); + buf.writeBoolean(false); + long l = 1L + Integer.MAX_VALUE; + buf.writeNumber(l); + buf.writeNumber((short) 4); + buf.writeNumber(0.5); + buf.writeEndArray(); + assertEquals(aposToQuotes("[true,false,"+l+",4,0.5]"), MAPPER.writeValueAsString(buf)); + buf.close(); + + buf = new TokenBuffer(MAPPER, false); + buf.writeStartObject(); + buf.writeFieldName(new SerializedString("foo")); + buf.writeNull(); + buf.writeFieldName("bar"); + buf.writeNumber(BigInteger.valueOf(123)); + buf.writeFieldName("dec"); + buf.writeNumber(BigDecimal.valueOf(5).movePointLeft(2)); + assertEquals(aposToQuotes("{'foo':null,'bar':123,'dec':0.05}"), MAPPER.writeValueAsString(buf)); + buf.close(); + } + /* /********************************************************** /* Tests to verify interaction of TokenBuffer and JsonParserSequence |