Skip to content

Commit 69e7bbf

Browse files
authored
Fix #497: add override for IonValueMapper.copy() (#498)
1 parent 56b01e3 commit 69e7bbf

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapper.java

+12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.io.IOException;
1818

19+
import com.fasterxml.jackson.databind.ObjectMapper;
1920
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
2021
import com.fasterxml.jackson.dataformat.ion.EnumAsIonSymbolModule;
2122
import com.fasterxml.jackson.dataformat.ion.IonFactory;
@@ -45,6 +46,11 @@ public IonValueMapper(IonSystem ionSystem) {
4546
this(ionSystem, null);
4647
}
4748

49+
// @since 2.18: needed for `copy()`
50+
protected IonValueMapper(IonValueMapper src) {
51+
super(src);
52+
}
53+
4854
/**
4955
* Constructor that provides an override on the default Constructor for the PropertyNamingStrategy.
5056
*
@@ -60,6 +66,12 @@ public IonValueMapper(IonSystem ionSystem, PropertyNamingStrategy strategy) {
6066
this.setPropertyNamingStrategy(strategy);
6167
}
6268

69+
@Override // @since 2.18
70+
public ObjectMapper copy() {
71+
_checkInvalidCopy(IonValueMapper.class);
72+
return new IonValueMapper(this);
73+
}
74+
6375
public <T> T parse(IonValue value, Class<T> clazz) throws IOException {
6476
if (value == null) {
6577
return null;

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/DataBindReadTest.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.junit.Test;
2020

2121
import com.fasterxml.jackson.annotation.JsonIgnore;
22-
22+
import com.fasterxml.jackson.databind.ObjectMapper;
2323
import com.amazon.ion.IonReader;
2424
import com.amazon.ion.IonStruct;
2525
import com.amazon.ion.IonSystem;
@@ -39,6 +39,15 @@ static class MyBean {
3939

4040
static class BeanToo { }
4141

42+
// Not the best place for test but will have to do
43+
@Test
44+
public void testMapperCopy() throws IOException
45+
{
46+
IonObjectMapper vanilla = IonObjectMapper.builder().build();
47+
ObjectMapper copy = vanilla.copy();
48+
assertNotSame(vanilla, copy);
49+
}
50+
4251
@Test
4352
public void testSimple() throws IOException
4453
{

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/ionvalue/IonValueMapperTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.junit.Assert.assertEquals;
1818
import static org.junit.Assert.assertFalse;
1919
import static org.junit.Assert.assertNotNull;
20+
import static org.junit.Assert.assertNotSame;
2021
import static org.junit.Assert.assertNull;
2122

2223
import java.io.IOException;
@@ -32,6 +33,7 @@
3233
import com.fasterxml.jackson.annotation.JsonProperty;
3334

3435
import com.fasterxml.jackson.databind.DeserializationFeature;
36+
import com.fasterxml.jackson.databind.ObjectMapper;
3537
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
3638
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
3739
import com.fasterxml.jackson.dataformat.ion.IonSymbolSerializer;
@@ -67,6 +69,12 @@ public static class TestPojo1 {
6769
public Timestamp someTime;
6870
}
6971

72+
@Test
73+
public void testMapperCopy() throws Exception {
74+
ObjectMapper mapper2 = ionValueMapper.copy();
75+
assertNotSame(ionValueMapper, mapper2);
76+
}
77+
7078
@Test
7179
public void testNull() throws Exception {
7280
assertNull(ionValueMapper.parse(null, TestPojo1.class));

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ Active maintainers:
1818

1919
- No changes since 2.17
2020

21+
2.17.2 (not yet released)
22+
23+
#497: (ion) Failed copy(): `IonValueMapper` does not override copy()
24+
(reported by @mr-robert)
25+
2126
2.17.1 (04-May-2024)
2227

2328
#487 (ion): Don't close IonParser on EOF to be compatible with `MappingIterator`

0 commit comments

Comments
 (0)