From 25818aa2829ba5f524a311eeadb9cc45a4c81cce Mon Sep 17 00:00:00 2001 From: Joshua Caplan Date: Mon, 12 Sep 2016 13:24:46 -0700 Subject: [PATCH 1/6] add @JsonIgnore to JsonMappingException --- .../com/fasterxml/jackson/databind/JsonMappingException.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java b/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java index 8a4ebb3da4..5d054a526d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java +++ b/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java @@ -189,6 +189,7 @@ Object writeReplace() { * * @since 2.7 */ + @JsonIgnore protected transient Closeable _processor; /* From f8d658dd1843b36fe5a97f10b28bcac65a7fc24f Mon Sep 17 00:00:00 2001 From: Joshua Caplan Date: Mon, 12 Sep 2016 13:28:45 -0700 Subject: [PATCH 2/6] Create TestJsonMappingException --- .../jackson/databind/TestJsonMappingException | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException diff --git a/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException b/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException new file mode 100644 index 0000000000..5e75518329 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException @@ -0,0 +1,24 @@ +package com.fasterxml.jackson.databind; + +import java.io.IOException; + +import org.junit.Test; + +public class TestJsonMappingException { + public static class NoSerdeConstructor { + private String strVal; + public String getVal() { return strVal; } + public NoSerdeConstructor( String strVal ) { + this.strVal = strVal; + } + } + @Test + public void test() throws IOException { + ObjectMapper mpr = new ObjectMapper(); + try { + mpr.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class ); + } catch ( JsonMappingException exc ) { + mpr.writeValueAsString( exc ); + } + } +} From 3fc9886566525e995f716845ba148f9a546548e1 Mon Sep 17 00:00:00 2001 From: Joshua Caplan Date: Mon, 12 Sep 2016 14:24:12 -0700 Subject: [PATCH 3/6] Create TestJsonMappingException.java --- .../databind/TestJsonMappingException.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java diff --git a/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java b/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java new file mode 100644 index 0000000000..5e75518329 --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java @@ -0,0 +1,24 @@ +package com.fasterxml.jackson.databind; + +import java.io.IOException; + +import org.junit.Test; + +public class TestJsonMappingException { + public static class NoSerdeConstructor { + private String strVal; + public String getVal() { return strVal; } + public NoSerdeConstructor( String strVal ) { + this.strVal = strVal; + } + } + @Test + public void test() throws IOException { + ObjectMapper mpr = new ObjectMapper(); + try { + mpr.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class ); + } catch ( JsonMappingException exc ) { + mpr.writeValueAsString( exc ); + } + } +} From 309e5338648c0d4c9a83f2ee9c91fa67f12e0686 Mon Sep 17 00:00:00 2001 From: Joshua Caplan Date: Mon, 12 Sep 2016 14:32:27 -0700 Subject: [PATCH 4/6] move annotation to getter --- .../com/fasterxml/jackson/databind/JsonMappingException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java b/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java index 5d054a526d..cc6fb5a21d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java +++ b/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java @@ -189,7 +189,6 @@ Object writeReplace() { * * @since 2.7 */ - @JsonIgnore protected transient Closeable _processor; /* @@ -455,6 +454,7 @@ public void prependPath(Reference r) /********************************************************** */ + @JsonIgnore @Override // since 2.7.5 public Object getProcessor() { return _processor; } From 91cf06e2e413e788a607cfa69301f149ce5719aa Mon Sep 17 00:00:00 2001 From: Joshua Caplan Date: Mon, 12 Sep 2016 14:33:32 -0700 Subject: [PATCH 5/6] delete misnamed file. new to this github stuff. --- .../jackson/databind/TestJsonMappingException | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException diff --git a/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException b/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException deleted file mode 100644 index 5e75518329..0000000000 --- a/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException +++ /dev/null @@ -1,24 +0,0 @@ -package com.fasterxml.jackson.databind; - -import java.io.IOException; - -import org.junit.Test; - -public class TestJsonMappingException { - public static class NoSerdeConstructor { - private String strVal; - public String getVal() { return strVal; } - public NoSerdeConstructor( String strVal ) { - this.strVal = strVal; - } - } - @Test - public void test() throws IOException { - ObjectMapper mpr = new ObjectMapper(); - try { - mpr.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class ); - } catch ( JsonMappingException exc ) { - mpr.writeValueAsString( exc ); - } - } -} From cb932a7b931f7f5b4bc9f49749976fe4c2f4e342 Mon Sep 17 00:00:00 2001 From: Joshua Caplan Date: Mon, 12 Sep 2016 14:45:00 -0700 Subject: [PATCH 6/6] separate JsonMappingException test into two tests Original form of test did not assert that the first attempt to serialize should cause a JsonMappingException --- .../jackson/databind/TestJsonMappingException.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java b/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java index 5e75518329..b0d6b0f346 100644 --- a/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java +++ b/src/test/java/com/fasterxml/jackson/databind/TestJsonMappingException.java @@ -12,12 +12,20 @@ public NoSerdeConstructor( String strVal ) { this.strVal = strVal; } } + // we know we can't serialize this dumb class above + @Test( expected = JsonMappingException.class ) + public void testNoSerdeConstructor() throws IOException { + ObjectMapper mpr = new ObjectMapper(); + mpr.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class ); + } + // we should, however, be able to serialize the exception arising from the above test @Test - public void test() throws IOException { + public void testJsonMappingExceptionIsJacksonSerializable() throws IOException { ObjectMapper mpr = new ObjectMapper(); try { - mpr.readValue( "{ \"val\": \"foo\" }", NoSerdeConstructor.class ); + testNoSerdeConstructor(); } catch ( JsonMappingException exc ) { + // without @JsonIgnore on getProcessor() this causes an error mpr.writeValueAsString( exc ); } }