diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java index c39755be4..3fc867990 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java @@ -43,17 +43,11 @@ public class CBORFactory */ public final static String FORMAT_NAME = "CBOR"; - /** - * Bitfield (set of flags) of all parser features that are enabled - * by default. - */ - final static int DEFAULT_CBOR_PARSER_FEATURE_FLAGS = CBORParser.Feature.collectDefaults(); - /** * Bitfield (set of flags) of all generator features that are enabled * by default. */ - final static int DEFAULT_CBOR_GENERATOR_FEATURE_FLAGS = CBORGenerator.Feature.collectDefaults(); + final static int DEFAULT_CBOR_GENERATOR_FEATURE_FLAGS = CBORWriteFeature.collectDefaults(); /* /********************************************************************** @@ -87,7 +81,7 @@ public CBORFactory() { super(StreamReadConstraints.defaults(), StreamWriteConstraints.defaults(), ErrorReportConfiguration.defaults(), - DEFAULT_CBOR_PARSER_FEATURE_FLAGS, + 0, DEFAULT_CBOR_GENERATOR_FEATURE_FLAGS); } @@ -179,27 +173,22 @@ public boolean canUseSchema(FormatSchema schema) { return false; // no (mandatory) FormatSchema for cbor } - @Override - public Class getFormatReadFeatureType() { - return CBORParser.Feature.class; + // No Reader features yet for CBOR + /*@Override + public Class getFormatReadFeatureType() { + return CBORReadFeature.class; } + */ @Override - public Class getFormatWriteFeatureType() { - return CBORGenerator.Feature.class; - } - - /** - * Checked whether specified parser feature is enabled. - */ - public final boolean isEnabled(CBORParser.Feature f) { - return f.enabledIn(_formatReadFeatures); + public Class getFormatWriteFeatureType() { + return CBORWriteFeature.class; } /** * Check whether specified generator feature is enabled. */ - public final boolean isEnabled(CBORGenerator.Feature f) { + public final boolean isEnabled(CBORWriteFeature f) { return f.enabledIn(_formatWriteFeatures); } @@ -267,10 +256,10 @@ protected JsonGenerator _createGenerator(ObjectWriteContext writeCtxt, writeCtxt.getStreamWriteFeatures(_streamWriteFeatures), writeCtxt.getFormatWriteFeatures(_formatWriteFeatures), out); - if (CBORGenerator.Feature.WRITE_TYPE_HEADER.enabledIn(_formatWriteFeatures)) { + if (CBORWriteFeature.WRITE_TYPE_HEADER.enabledIn(_formatWriteFeatures)) { gen.writeTag(CBORConstants.TAG_ID_SELF_DESCRIBE); } - if (CBORGenerator.Feature.STRINGREF.enabledIn(_formatWriteFeatures)) { + if (CBORWriteFeature.STRINGREF.enabledIn(_formatWriteFeatures)) { gen.writeTag(CBORConstants.TAG_ID_STRINGREF_NAMESPACE); } return gen; diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactoryBuilder.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactoryBuilder.java index 6f990e098..17df0c07f 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactoryBuilder.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactoryBuilder.java @@ -24,7 +24,7 @@ protected CBORFactoryBuilder() { super(StreamReadConstraints.defaults(), StreamWriteConstraints.defaults(), ErrorReportConfiguration.defaults(), - CBORFactory.DEFAULT_CBOR_PARSER_FEATURE_FLAGS, + 0, CBORFactory.DEFAULT_CBOR_GENERATOR_FEATURE_FLAGS); } @@ -32,67 +32,35 @@ public CBORFactoryBuilder(CBORFactory base) { super(base); } - // // // Parser features - - public CBORFactoryBuilder enable(CBORParser.Feature f) { - _formatReadFeatures |= f.getMask(); - return _this(); - } - - public CBORFactoryBuilder enable(CBORParser.Feature first, CBORParser.Feature... other) { - _formatReadFeatures |= first.getMask(); - for (CBORParser.Feature f : other) { - _formatReadFeatures |= f.getMask(); - } - return _this(); - } - - public CBORFactoryBuilder disable(CBORParser.Feature f) { - _formatReadFeatures &= ~f.getMask(); - return _this(); - } - - public CBORFactoryBuilder disable(CBORParser.Feature first, CBORParser.Feature... other) { - _formatReadFeatures &= ~first.getMask(); - for (CBORParser.Feature f : other) { - _formatReadFeatures &= ~f.getMask(); - } - return _this(); - } - - public CBORFactoryBuilder configure(CBORParser.Feature f, boolean state) { - return state ? enable(f) : disable(f); - } - // // // Generator features - public CBORFactoryBuilder enable(CBORGenerator.Feature f) { + public CBORFactoryBuilder enable(CBORWriteFeature f) { _formatWriteFeatures |= f.getMask(); return _this(); } - public CBORFactoryBuilder enable(CBORGenerator.Feature first, CBORGenerator.Feature... other) { + public CBORFactoryBuilder enable(CBORWriteFeature first, CBORWriteFeature... other) { _formatWriteFeatures |= first.getMask(); - for (CBORGenerator.Feature f : other) { + for (CBORWriteFeature f : other) { _formatWriteFeatures |= f.getMask(); } return _this(); } - public CBORFactoryBuilder disable(CBORGenerator.Feature f) { + public CBORFactoryBuilder disable(CBORWriteFeature f) { _formatWriteFeatures &= ~f.getMask(); return _this(); } - public CBORFactoryBuilder disable(CBORGenerator.Feature first, CBORGenerator.Feature... other) { + public CBORFactoryBuilder disable(CBORWriteFeature first, CBORWriteFeature... other) { _formatWriteFeatures &= ~first.getMask(); - for (CBORGenerator.Feature f : other) { + for (CBORWriteFeature f : other) { _formatWriteFeatures &= ~f.getMask(); } return _this(); } - public CBORFactoryBuilder configure(CBORGenerator.Feature f, boolean state) { + public CBORFactoryBuilder configure(CBORWriteFeature f, boolean state) { return state ? enable(f) : disable(f); } diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORGenerator.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORGenerator.java index 5963a1977..7ed3335b8 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORGenerator.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORGenerator.java @@ -49,106 +49,6 @@ public class CBORGenerator extends GeneratorBase */ private final static int MAX_LONG_STRING_BYTES = (MAX_LONG_STRING_CHARS * 3) + 3; - /** - * Enumeration that defines all togglable features for CBOR generator. - */ - public enum Feature implements FormatFeature { - /** - * Feature that determines whether generator should try to use smallest - * (size-wise) integer representation: if true, will use smallest - * representation that is enough to retain value; if false, will use - * length indicated by argument type (4-byte for int, - * 8-byte for long and so on). - */ - WRITE_MINIMAL_INTS(true), - - /** - * Feature that determines whether CBOR "Self-Describe Tag" (value - * 55799, encoded as 3-byte sequence of 0xD9, 0xD9, 0xF7) - * should be written at the beginning of document or not. - *

- * Default value is {@code false} meaning that type tag will not be - * written at the beginning of a new document. - */ - WRITE_TYPE_HEADER(false), - - /** - * Feature that determines if an invalid surrogate encoding found in the - * incoming String should fail with an exception or silently be output - * as the Unicode 'REPLACEMENT CHARACTER' (U+FFFD) or not; if not, - * an exception will be thrown to indicate invalid content. - *

- * Default value is {@code false} (for backwards compatibility) meaning that - * an invalid surrogate will result in exception ({@code StreamWriteException}). - */ - LENIENT_UTF_ENCODING(false), - - /** - * Feature that determines if string references are generated based on the - * stringref) extension. This can save - * storage space, parsing time, and pool string memory when parsing. Readers of the output - * must also support the stringref extension to properly decode the data. Extra overhead may - * be added to generation time and memory usage to compute the shared binary and text - * strings. - *

- * Default value is {@code false} meaning that the stringref extension will not be used. - * - * @since 2.15 - */ - STRINGREF(false), - - /** - * Feature that determines whether generator should try to write doubles - * as floats: if {@code true}, will write a {@code double} as a 4-byte float if no - * precision loss will occur; if {@code false}, will always write a {@code double} - * as an 8-byte double. - *

- * Default value is {@code false} meaning that doubles will always be written as - * 8-byte values. - * - * @since 2.15 - */ - WRITE_MINIMAL_DOUBLES(false), - ; - - protected final boolean _defaultState; - protected final int _mask; - - /** - * Method that calculates bit set (flags) of all features that are - * enabled by default. - */ - public static int collectDefaults() { - int flags = 0; - for (Feature f : values()) { - if (f.enabledByDefault()) { - flags |= f.getMask(); - } - } - return flags; - } - - private Feature(boolean defaultState) { - _defaultState = defaultState; - _mask = (1 << ordinal()); - } - - @Override - public boolean enabledByDefault() { - return _defaultState; - } - - @Override - public boolean enabledIn(int flags) { - return (flags & getMask()) != 0; - } - - @Override - public int getMask() { - return _mask; - } - } - /** * To simplify certain operations, we require output buffer length to allow * outputting of contiguous 256 character UTF-8 encoded String value. Length @@ -176,7 +76,7 @@ public int getMask() { /** * Bit flag composed of bits that indicate which - * {@link CBORGenerator.Feature}s are enabled. + * {@link CBORWriteFeature}s are enabled. */ protected final int _formatFeatures; @@ -280,11 +180,11 @@ public CBORGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, ? DupDetector.rootDetector(this) : null; _streamWriteContext = CBORWriteContext.createRootContext(dups); - _cfgMinimalInts = Feature.WRITE_MINIMAL_INTS.enabledIn(formatFeatures); - _cfgMinimalDoubles = Feature.WRITE_MINIMAL_DOUBLES.enabledIn(formatFeatures); + _cfgMinimalInts = CBORWriteFeature.WRITE_MINIMAL_INTS.enabledIn(formatFeatures); + _cfgMinimalDoubles = CBORWriteFeature.WRITE_MINIMAL_DOUBLES.enabledIn(formatFeatures); _out = out; _bufferRecyclable = true; - _stringRefs = Feature.STRINGREF.enabledIn(formatFeatures) ? new HashMap<>() : null; + _stringRefs = CBORWriteFeature.STRINGREF.enabledIn(formatFeatures) ? new HashMap<>() : null; _outputBuffer = ioCtxt.allocWriteEncodingBuffer(BYTE_BUFFER_FOR_OUTPUT); _outputEnd = _outputBuffer.length; _charBuffer = ioCtxt.allocConcatBuffer(); @@ -317,13 +217,13 @@ public CBORGenerator(ObjectWriteContext writeCtxt, IOContext ioCtxt, ? DupDetector.rootDetector(this) : null; _streamWriteContext = CBORWriteContext.createRootContext(dups); - _cfgMinimalInts = Feature.WRITE_MINIMAL_INTS.enabledIn(formatFeatures); - _cfgMinimalDoubles = Feature.WRITE_MINIMAL_DOUBLES.enabledIn(formatFeatures); + _cfgMinimalInts = CBORWriteFeature.WRITE_MINIMAL_INTS.enabledIn(formatFeatures); + _cfgMinimalDoubles = CBORWriteFeature.WRITE_MINIMAL_DOUBLES.enabledIn(formatFeatures); _out = out; _bufferRecyclable = bufferRecyclable; _outputTail = offset; _outputBuffer = outputBuffer; - _stringRefs = Feature.STRINGREF.enabledIn(formatFeatures) ? new HashMap<>() : null; + _stringRefs = CBORWriteFeature.STRINGREF.enabledIn(formatFeatures) ? new HashMap<>() : null; _outputEnd = _outputBuffer.length; _charBuffer = ioCtxt.allocConcatBuffer(); _charBufferLength = _charBuffer.length; @@ -422,7 +322,7 @@ public CBORGenerator disable(Feature f) { } */ - public final boolean isEnabled(Feature f) { + public final boolean isEnabled(CBORWriteFeature f) { return (_formatFeatures & f.getMask()) != 0; } @@ -1653,7 +1553,7 @@ private final int _encode2(int i, int outputPtr, String str, int len, private int _invalidSurrogateStart(int code, byte[] outBuf, int outputPtr) throws JacksonException { - if (isEnabled(Feature.LENIENT_UTF_ENCODING)) { + if (isEnabled(CBORWriteFeature.LENIENT_UTF_ENCODING)) { return _appendReplacementChar(outBuf, outputPtr); } // Will be called in two distinct cases: either first character is @@ -1675,7 +1575,7 @@ private int _invalidSurrogateEnd(int surr1, int surr2, byte[] outBuf, int outputPtr) throws JacksonException { - if (isEnabled(Feature.LENIENT_UTF_ENCODING)) { + if (isEnabled(CBORWriteFeature.LENIENT_UTF_ENCODING)) { return _appendReplacementChar(outBuf, outputPtr); } _reportError(String.format( diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java index f8811f76f..5d05aabca 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORParser.java @@ -24,46 +24,8 @@ public class CBORParser extends ParserBase { - /** - * Enumeration that defines all togglable features for CBOR generators. - */ - public enum Feature implements FormatFeature - { -// BOGUS(false) - ; - - final boolean _defaultState; - final int _mask; - - /** - * Method that calculates bit set (flags) of all features that - * are enabled by default. - */ - public static int collectDefaults() - { - int flags = 0; - for (Feature f : values()) { - if (f.enabledByDefault()) { - flags |= f.getMask(); - } - } - return flags; - } - - private Feature(boolean defaultState) { - _defaultState = defaultState; - _mask = (1 << ordinal()); - } - - @Override public boolean enabledByDefault() { return _defaultState; } - @Override public int getMask() { return _mask; } - @Override public boolean enabledIn(int flags) { return (flags & _mask) != 0; } - } - /** * Class for keeping track of tags in an optimized manner. - * - * @since 2.15 */ public static final class TagList { diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORWriteFeature.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORWriteFeature.java new file mode 100644 index 000000000..bb59216ab --- /dev/null +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/CBORWriteFeature.java @@ -0,0 +1,102 @@ +package tools.jackson.dataformat.cbor; + +import tools.jackson.core.FormatFeature; + +/** + * Enumeration that defines all togglable features for CBOR generator. + *

+ * NOTE: in Jackson 2.x this was named {@code CBORParser.Feature}. + */ +public enum CBORWriteFeature implements FormatFeature +{ + /** + * Feature that determines whether generator should try to use smallest + * (size-wise) integer representation: if true, will use smallest + * representation that is enough to retain value; if false, will use + * length indicated by argument type (4-byte for int, + * 8-byte for long and so on). + */ + WRITE_MINIMAL_INTS(true), + + /** + * Feature that determines whether CBOR "Self-Describe Tag" (value + * 55799, encoded as 3-byte sequence of 0xD9, 0xD9, 0xF7) + * should be written at the beginning of document or not. + *

+ * Default value is {@code false} meaning that type tag will not be + * written at the beginning of a new document. + */ + WRITE_TYPE_HEADER(false), + + /** + * Feature that determines if an invalid surrogate encoding found in the + * incoming String should fail with an exception or silently be output + * as the Unicode 'REPLACEMENT CHARACTER' (U+FFFD) or not; if not, + * an exception will be thrown to indicate invalid content. + *

+ * Default value is {@code false} (for backwards compatibility) meaning that + * an invalid surrogate will result in exception ({@code StreamWriteException}). + */ + LENIENT_UTF_ENCODING(false), + + /** + * Feature that determines if string references are generated based on the + * stringref) extension. This can save + * storage space, parsing time, and pool string memory when parsing. Readers of the output + * must also support the stringref extension to properly decode the data. Extra overhead may + * be added to generation time and memory usage to compute the shared binary and text + * strings. + *

+ * Default value is {@code false} meaning that the stringref extension will not be used. + */ + STRINGREF(false), + + /** + * Feature that determines whether generator should try to write doubles + * as floats: if {@code true}, will write a {@code double} as a 4-byte float if no + * precision loss will occur; if {@code false}, will always write a {@code double} + * as an 8-byte double. + *

+ * Default value is {@code false} meaning that doubles will always be written as + * 8-byte values. + */ + WRITE_MINIMAL_DOUBLES(false), + ; + + private final boolean _defaultState; + private final int _mask; + + /** + * Method that calculates bit set (flags) of all features that are + * enabled by default. + */ + public static int collectDefaults() { + int flags = 0; + for (CBORWriteFeature f : values()) { + if (f.enabledByDefault()) { + flags |= f.getMask(); + } + } + return flags; + } + + private CBORWriteFeature(boolean defaultState) { + _defaultState = defaultState; + _mask = (1 << ordinal()); + } + + @Override + public boolean enabledByDefault() { + return _defaultState; + } + + @Override + public boolean enabledIn(int flags) { + return (flags & getMask()) != 0; + } + + @Override + public int getMask() { + return _mask; + } +} diff --git a/cbor/src/main/java/tools/jackson/dataformat/cbor/databind/CBORMapper.java b/cbor/src/main/java/tools/jackson/dataformat/cbor/databind/CBORMapper.java index 6563b5e01..338b3a6e6 100644 --- a/cbor/src/main/java/tools/jackson/dataformat/cbor/databind/CBORMapper.java +++ b/cbor/src/main/java/tools/jackson/dataformat/cbor/databind/CBORMapper.java @@ -7,7 +7,7 @@ import tools.jackson.databind.cfg.MapperBuilderState; import tools.jackson.dataformat.cbor.CBORFactory; -import tools.jackson.dataformat.cbor.CBORGenerator; +import tools.jackson.dataformat.cbor.CBORWriteFeature; import tools.jackson.dataformat.cbor.PackageVersion; /** @@ -74,21 +74,21 @@ public Builder configure(CBORParser.Feature feature, boolean state) } */ - public Builder enable(CBORGenerator.Feature... features) { - for (CBORGenerator.Feature f : features) { + public Builder enable(CBORWriteFeature... features) { + for (CBORWriteFeature f : features) { _formatWriteFeatures |= f.getMask(); } return this; } - public Builder disable(CBORGenerator.Feature... features) { - for (CBORGenerator.Feature f : features) { + public Builder disable(CBORWriteFeature... features) { + for (CBORWriteFeature f : features) { _formatWriteFeatures &= ~f.getMask(); } return this; } - public Builder configure(CBORGenerator.Feature feature, boolean state) + public Builder configure(CBORWriteFeature feature, boolean state) { if (state) { _formatWriteFeatures |= feature.getMask(); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java index b5bdf2ec3..035241f77 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORFactoryPropertiesTest.java @@ -72,8 +72,8 @@ public void testVersions() throws Exception public void testCapabilities() throws Exception { assertTrue(CBOR_F.canHandleBinaryNatively()); - assertEquals(CBORParser.Feature.class, CBOR_F.getFormatReadFeatureType()); - assertEquals(CBORGenerator.Feature.class, CBOR_F.getFormatWriteFeatureType()); + assertEquals(null, CBOR_F.getFormatReadFeatureType()); + assertEquals(CBORWriteFeature.class, CBOR_F.getFormatWriteFeatureType()); } public void testInabilityToReadChars() throws Exception diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORTestBase.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORTestBase.java index 0800fb6ea..a6b61243f 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORTestBase.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/CBORTestBase.java @@ -165,7 +165,7 @@ protected void _copy(JsonParser p, JsonGenerator g) protected CBORGenerator lenientUnicodeCborGenerator(ByteArrayOutputStream result) { return (CBORGenerator) cborFactoryBuilder() - .enable(CBORGenerator.Feature.LENIENT_UTF_ENCODING) + .enable(CBORWriteFeature.LENIENT_UTF_ENCODING) .build() .createGenerator(ObjectWriteContext.empty(), result); } @@ -175,7 +175,7 @@ protected CBORGenerator stringrefCborGenerator(ByteArrayOutputStream result) throws IOException { return (CBORGenerator) cborFactoryBuilder() - .enable(CBORGenerator.Feature.STRINGREF) + .enable(CBORWriteFeature.STRINGREF) .build() .createGenerator(ObjectWriteContext.empty(), result); } diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/GeneratorInteropTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/GeneratorInteropTest.java index 1a952c17f..3191f40e1 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/GeneratorInteropTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/GeneratorInteropTest.java @@ -34,7 +34,7 @@ public void testAutoTypeDescription() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); CBORFactory f = cborFactory(); - assertFalse(f.isEnabled(CBORGenerator.Feature.WRITE_TYPE_HEADER)); + assertFalse(f.isEnabled(CBORWriteFeature.WRITE_TYPE_HEADER)); CBORGenerator gen = (CBORGenerator) f.createGenerator(ObjectWriteContext.empty(), out); // First, without feature, we get just a single byte doc @@ -46,7 +46,7 @@ public void testAutoTypeDescription() throws Exception }); f = f.rebuild() - .enable(CBORGenerator.Feature.WRITE_TYPE_HEADER) + .enable(CBORWriteFeature.WRITE_TYPE_HEADER) .build(); // but with auto-write out = new ByteArrayOutputStream(); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/NumberCoercing32Test.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/NumberCoercing32Test.java index e4eff5cad..5961ed99b 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/NumberCoercing32Test.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/NumberCoercing32Test.java @@ -9,7 +9,7 @@ public class NumberCoercing32Test extends CBORTestBase public void testPrimitiveTypeInvariance() throws Exception { ObjectMapper mapper = new ObjectMapper(CBORFactory.builder() - .disable(CBORGenerator.Feature.WRITE_MINIMAL_INTS) + .disable(CBORWriteFeature.WRITE_MINIMAL_INTS) .build()); Map map = new HashMap<>(); map.put("longField", 1L); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java index 14aa9f85f..9ab21406e 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/ParserWithJsonOrgSampleTest.java @@ -23,7 +23,7 @@ public void testJsonSampleDoc() throws IOException public void testJsonSampleDocStringref() throws IOException { CBORMapper cborMapper = new CBORMapper(cborFactoryBuilder() - .enable(CBORGenerator.Feature.STRINGREF).build()); + .enable(CBORWriteFeature.STRINGREF).build()); byte[] data = cborDoc(cborMapper, SAMPLE_DOC_JSON_SPEC); verifyJsonSpecSampleDoc(cborParser(data), true, true); verifyJsonSpecSampleDoc(cborParser(data), true, false); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/StringrefTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/StringrefTest.java index 7eeb4f80d..f0f27e802 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/StringrefTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/StringrefTest.java @@ -19,7 +19,7 @@ public class StringrefTest extends CBORTestBase public void testSimpleObject() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); gen.writeStartObject(); @@ -101,7 +101,7 @@ public void testSimpleObjectSerializedStrings() throws Exception { // SerializableString interface takes different code paths. ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); gen.writeStartObject(); @@ -190,7 +190,7 @@ public void testSimpleObjectSerializedStrings() throws Exception { public void testStringArray() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); gen.writeString("1"); @@ -235,7 +235,7 @@ public void testStringArray() throws Exception { public void testStringArrayFromChars() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); writeStringAsCharArray(gen, "1"); @@ -280,7 +280,7 @@ public void testStringArrayFromChars() throws Exception { public void testStringArraySerializedString() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); gen.writeString(new SerializedString("1")); @@ -325,7 +325,7 @@ public void testStringArraySerializedString() throws Exception { public void testStringArrayUTF8() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); writeStringAsUTF8(gen, "1"); @@ -410,7 +410,7 @@ public void testStringArrayNextTextValue() throws Exception { public void testBinaryStringArray() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); writeStringAsBinary(gen, "1"); @@ -490,7 +490,7 @@ public void testBinaryStringArray() throws Exception { public void testBinaryStringArrayStream() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = stringrefCborGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.STRINGREF)); + assertTrue(gen.isEnabled(CBORWriteFeature.STRINGREF)); gen.writeStartArray(); writeStringAsBinaryStream(gen, "1"); @@ -598,8 +598,8 @@ public void testNestedNamespaces() throws Exception { public void testNestedTags() throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = (CBORGenerator) CBORFactory.builder() - .enable(CBORGenerator.Feature.WRITE_TYPE_HEADER) - .enable(CBORGenerator.Feature.STRINGREF) + .enable(CBORWriteFeature.WRITE_TYPE_HEADER) + .enable(CBORWriteFeature.STRINGREF) .build() .createGenerator(ObjectWriteContext.empty(), bytes); @@ -647,8 +647,8 @@ public void testNestedTagsRounddTrip() throws Exception { bytes.reset(); parser = cborParser(encoded); gen = (CBORGenerator) CBORFactory.builder() - .enable(CBORGenerator.Feature.WRITE_TYPE_HEADER) - .enable(CBORGenerator.Feature.STRINGREF) + .enable(CBORWriteFeature.WRITE_TYPE_HEADER) + .enable(CBORWriteFeature.STRINGREF) .build() .createGenerator(ObjectWriteContext.empty(), bytes); parser.nextToken(); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/ArrayGenerationTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/ArrayGenerationTest.java index c04a9e9d3..921253ac7 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/ArrayGenerationTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/ArrayGenerationTest.java @@ -9,6 +9,7 @@ import tools.jackson.dataformat.cbor.CBORGenerator; import tools.jackson.dataformat.cbor.CBORParser; import tools.jackson.dataformat.cbor.CBORTestBase; +import tools.jackson.dataformat.cbor.CBORWriteFeature; import tools.jackson.dataformat.cbor.databind.CBORMapper; /** @@ -48,7 +49,7 @@ private void _testMinimalIntValuesForInt(int v1, int v2, final int[] input = new int[] { v1, v2 }; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = (CBORGenerator) MAPPER.createGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.WRITE_MINIMAL_INTS)); + assertTrue(gen.isEnabled(CBORWriteFeature.WRITE_MINIMAL_INTS)); gen.writeArray(input, 0, 2); gen.close(); @@ -73,9 +74,9 @@ private void _testMinimalIntValuesForInt(int v1, int v2, bytes = new ByteArrayOutputStream(); gen = (CBORGenerator) MAPPER .writer() - .without(CBORGenerator.Feature.WRITE_MINIMAL_INTS) + .without(CBORWriteFeature.WRITE_MINIMAL_INTS) .createGenerator(bytes); - assertFalse(gen.isEnabled(CBORGenerator.Feature.WRITE_MINIMAL_INTS)); + assertFalse(gen.isEnabled(CBORWriteFeature.WRITE_MINIMAL_INTS)); gen.writeArray(input, 0, 2); gen.close(); @@ -108,7 +109,7 @@ public void testMinimalIntValuesForLong() throws Exception }; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); CBORGenerator gen = (CBORGenerator) MAPPER.createGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.WRITE_MINIMAL_INTS)); + assertTrue(gen.isEnabled(CBORWriteFeature.WRITE_MINIMAL_INTS)); gen.writeArray(input, 0, 2); gen.close(); @@ -132,7 +133,7 @@ public void testMinimalIntValuesForLong() throws Exception // but then also check without minimization bytes = new ByteArrayOutputStream(); gen = (CBORGenerator) MAPPER.writer() - .without(CBORGenerator.Feature.WRITE_MINIMAL_INTS) + .without(CBORWriteFeature.WRITE_MINIMAL_INTS) .createGenerator(bytes); gen.writeArray(input, 0, 2); @@ -166,11 +167,11 @@ public void testMinimalFloatValuesForDouble() throws Exception }; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); final ObjectMapper mapperWithMinimalFloats = cborMapper( - cborFactoryBuilder().enable(CBORGenerator.Feature.WRITE_MINIMAL_DOUBLES) + cborFactoryBuilder().enable(CBORWriteFeature.WRITE_MINIMAL_DOUBLES) .build()); CBORGenerator gen = (CBORGenerator) mapperWithMinimalFloats.createGenerator(bytes); - assertTrue(gen.isEnabled(CBORGenerator.Feature.WRITE_MINIMAL_DOUBLES)); + assertTrue(gen.isEnabled(CBORWriteFeature.WRITE_MINIMAL_DOUBLES)); gen.writeArray(input, 0, 2); gen.close(); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java index 1c7ce8402..acd24bbac 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/gen/GeneratorSimpleTest.java @@ -14,13 +14,14 @@ import tools.jackson.dataformat.cbor.CBORGenerator; import tools.jackson.dataformat.cbor.CBORParser; import tools.jackson.dataformat.cbor.CBORTestBase; +import tools.jackson.dataformat.cbor.CBORWriteFeature; public class GeneratorSimpleTest extends CBORTestBase { private final ObjectMapper MAPPER = cborMapper(); private final ObjectMapper MAPPER_NO_MINIMAL_INT = cborMapper( - cborFactoryBuilder().disable(CBORGenerator.Feature.WRITE_MINIMAL_INTS) + cborFactoryBuilder().disable(CBORWriteFeature.WRITE_MINIMAL_INTS) .build()); /** @@ -57,7 +58,7 @@ public void testMinimalIntValues() throws Exception ByteArrayOutputStream out = new ByteArrayOutputStream(); CBORGenerator gen = (CBORGenerator) MAPPER.createGenerator(out); - assertTrue(gen.isEnabled(CBORGenerator.Feature.WRITE_MINIMAL_INTS)); + assertTrue(gen.isEnabled(CBORWriteFeature.WRITE_MINIMAL_INTS)); gen.writeNumber(17); gen.close(); _verifyBytes(out.toByteArray(), diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/BiggerDataTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/BiggerDataTest.java index dff157753..6273a759b 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/BiggerDataTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/BiggerDataTest.java @@ -3,8 +3,8 @@ import java.util.*; import tools.jackson.databind.*; -import tools.jackson.dataformat.cbor.CBORGenerator; import tools.jackson.dataformat.cbor.CBORTestBase; +import tools.jackson.dataformat.cbor.CBORWriteFeature; import tools.jackson.dataformat.cbor.databind.CBORMapper; /** @@ -143,7 +143,7 @@ public void testRoundTripStringref() throws Exception Citm citm0 = jsonMapper().readValue(getClass().getResourceAsStream("/data/citm_catalog.json"), Citm.class); ObjectMapper mapper = new CBORMapper( - cborFactoryBuilder().enable(CBORGenerator.Feature.STRINGREF).build()); + cborFactoryBuilder().enable(CBORWriteFeature.STRINGREF).build()); byte[] cbor = mapper.writeValueAsBytes(citm0); Citm citm = mapper.readValue(cbor, Citm.class); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java index 332759773..c0ce11188 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/CBORMapperTest.java @@ -1,7 +1,7 @@ package tools.jackson.dataformat.cbor.mapper; -import tools.jackson.dataformat.cbor.CBORGenerator; import tools.jackson.dataformat.cbor.CBORTestBase; +import tools.jackson.dataformat.cbor.CBORWriteFeature; import tools.jackson.dataformat.cbor.databind.CBORMapper; import org.junit.Assert; @@ -24,15 +24,15 @@ public void testStreamingFeaturesViaMapper() throws Exception Object[] minimalValues = { SMALL_INT, BIG_INT, (float)LOW_RPECISION_DOUBLE, HIGH_RPECISION_DOUBLE}; CBORMapper mapperWithMinimal = CBORMapper.builder() - .enable(CBORGenerator.Feature.WRITE_MINIMAL_INTS) - .enable(CBORGenerator.Feature.WRITE_MINIMAL_DOUBLES) + .enable(CBORWriteFeature.WRITE_MINIMAL_INTS) + .enable(CBORWriteFeature.WRITE_MINIMAL_DOUBLES) .build(); byte[] encodedMinimal = mapperWithMinimal.writeValueAsBytes(values); assertEquals(21, encodedMinimal.length); CBORMapper mapperFull = CBORMapper.builder() - .disable(CBORGenerator.Feature.WRITE_MINIMAL_INTS) - .disable(CBORGenerator.Feature.WRITE_MINIMAL_DOUBLES) + .disable(CBORWriteFeature.WRITE_MINIMAL_INTS) + .disable(CBORWriteFeature.WRITE_MINIMAL_DOUBLES) .build(); byte[] encodedNotMinimal = mapperFull.writeValueAsBytes(values); assertEquals(29, encodedNotMinimal.length); diff --git a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/NumberBeanTest.java b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/NumberBeanTest.java index a6e1bd7ba..cf605dca6 100644 --- a/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/NumberBeanTest.java +++ b/cbor/src/test/java/tools/jackson/dataformat/cbor/mapper/NumberBeanTest.java @@ -15,6 +15,7 @@ import tools.jackson.dataformat.cbor.CBORGenerator; import tools.jackson.dataformat.cbor.CBORParser; import tools.jackson.dataformat.cbor.CBORTestBase; +import tools.jackson.dataformat.cbor.CBORWriteFeature; public class NumberBeanTest extends CBORTestBase { @@ -182,7 +183,7 @@ public void testNumberTypeRetainingBuffering() throws Exception ByteArrayOutputStream bytes; ObjectWriter w = MAPPER.writer() - .without(CBORGenerator.Feature.WRITE_MINIMAL_INTS); + .without(CBORWriteFeature.WRITE_MINIMAL_INTS); final BigDecimal EXP_BIG_DEC = new BigDecimal("0.0100"); bytes = new ByteArrayOutputStream(); diff --git a/release-notes/VERSION b/release-notes/VERSION index 01a31b5c0..899d25e06 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -22,3 +22,4 @@ implementations) #245: (ion) Pretty-printing not working Ion/text backend #522: JSTEP-8: rename `AvroParser.Feature` as `AvroReadFeature`, `AvroGenerator.Feature` as `AvroWriteFeature` +#524: JSTEP-8: rename `CBORGenerator.Feature` as `CBORWriteFeature`