Skip to content

Commit 6375988

Browse files
authored
Fix #669: CBOR, string ref (#670)
1 parent 24e487f commit 6375988

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

cbor/src/main/java/tools/jackson/dataformat/cbor/CBORFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ protected JsonGenerator _createGenerator(ObjectWriteContext writeCtxt,
269269
writeCtxt.getStreamWriteFeatures(_streamWriteFeatures),
270270
writeCtxt.getFormatWriteFeatures(_formatWriteFeatures),
271271
out);
272-
if (CBORWriteFeature.WRITE_TYPE_HEADER.enabledIn(_formatWriteFeatures)) {
272+
if (gen.isEnabled(CBORWriteFeature.WRITE_TYPE_HEADER)) {
273273
gen.writeTag(CBORConstants.TAG_ID_SELF_DESCRIBE);
274274
}
275-
if (CBORWriteFeature.STRINGREF.enabledIn(_formatWriteFeatures)) {
275+
if (gen.isEnabled(CBORWriteFeature.STRINGREF)) {
276276
gen.writeTag(CBORConstants.TAG_ID_STRINGREF_NAMESPACE);
277277
}
278278
return gen;

cbor/src/test/java/tools/jackson/dataformat/cbor/StringRef599Test.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tools.jackson.dataformat.cbor;
22

33
import java.util.Arrays;
4+
import java.util.List;
45

56
import org.junit.jupiter.api.Test;
67

@@ -32,6 +33,19 @@ public void testDupsWithStringRef() throws Exception
3233
_testStringRef(REF_MAPPER);
3334
}
3435

36+
// [dataformats-binary#669]: STRINGREF enabled via mapper builder (not factory builder)
37+
@Test
38+
public void testDupsWithStringRefViaMapperBuilder() throws Exception
39+
{
40+
ObjectMapper mapper = CBORMapper.builder()
41+
.enable(CBORWriteFeature.STRINGREF)
42+
.build();
43+
List<?> original = Arrays.asList("foo", "foo");
44+
byte[] cbor = mapper.writeValueAsBytes(original);
45+
List<?> deserialized = mapper.readValue(cbor, List.class);
46+
assertEquals(original, deserialized);
47+
}
48+
3549
private void _testStringRef(ObjectMapper mapper) throws Exception
3650
{
3751
byte[] cbor = mapper.writeValueAsBytes(Arrays.asList("foo", "foo"));

release-notes/CREDITS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ Michael Liedtke (@mcliedtke)
3333

3434
* Contributed #629: (ion) Unnecessary `IOException` in `IonObjectMapper` method signatures
3535
(3.1.0)
36+
37+
Klaus Meinhardt (@ajafff)
38+
39+
* Reported #669: STRINGREF String reference outside of a namespace
40+
(3.1.1)
41+

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ No changes since 3.1
2121
3.1.1 (not yet released)
2222

2323
#387: Avro generator should enforce `StreamWriteConstraints.maxNestingDepth`
24+
#669: STRINGREF String reference outside of a namespace
25+
(reported by Klaus M)
26+
(fix by @cowtowncoder, w/ Claude code)
2427

2528
3.1.0 (23-Feb-2026)
2629

0 commit comments

Comments
 (0)