[johnzon] branch master updated: adding a test showing the PR review comment and why current exception handling is not yet release ready
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new c2bf6945 adding a test showing the PR review comment and why current exception handling is not yet release ready c2bf6945 is described below commit c2bf6945c2ca43befa93e15d821e0dee439aa8de Author: Romain Manni-Bucau AuthorDate: Mon May 16 08:53:12 2022 +0200 adding a test showing the PR review comment and why current exception handling is not yet release ready --- .../MapperBeanConstructorExceptionsTest.java | 66 ++ 1 file changed, 66 insertions(+) diff --git a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperBeanConstructorExceptionsTest.java b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperBeanConstructorExceptionsTest.java index 2615fe0a..3abb1ce6 100644 --- a/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperBeanConstructorExceptionsTest.java +++ b/johnzon-mapper/src/test/java/org/apache/johnzon/mapper/MapperBeanConstructorExceptionsTest.java @@ -20,11 +20,50 @@ import org.junit.Test; import java.beans.ConstructorProperties; import java.lang.reflect.Type; +import java.util.Collection; +import java.util.Iterator; +import java.util.Spliterator; + +import static java.util.Spliterators.spliteratorUnknownSize; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; public class MapperBeanConstructorExceptionsTest { private static final RuntimeException USER_EXCEPTION = new RuntimeException("I am user, hear me roar"); +@Test +public void singleExceptionMapperInCause() { +try (final Mapper mapper = new MapperBuilder().setSnippetMaxLength(20).build()) { +mapper.readObject("{ \"string\" : \"whatever\" }", Rectangle.class); +fail("should have failed"); +} catch (final MapperException me) { +final Collection exceptionStack = stream(spliteratorUnknownSize(new Iterator() { +private Throwable current = me; + +@Override +public boolean hasNext() { +return current != null; +} + +@Override +public Throwable next() { +final Throwable throwable = current; +current = current.getCause() == current ? null : current.getCause(); +return throwable; +} +}, Spliterator.IMMUTABLE), false).collect(toList()); +assertEquals(3, exceptionStack.size()); + +// warn: this *must* be 1 which requires to ensure the MapperException thrown by +// org.apache.johnzon.mapper.MappingParserImpl.toValue is mutable to add the context/right message +// (no need to strip it, an alternative could be to use addSuppressed but it would keep creating stacks for nothing) +assertEquals(2, exceptionStack.stream().filter(MapperException.class::isInstance).count()); +} +} + @Test public void constructor() { ExceptionAsserts.fromMapperReadObject("{ \"string\" : \"Supercalifragilisticexpialidocious\" }", Circle.class) @@ -105,6 +144,23 @@ public class MapperBeanConstructorExceptionsTest { } } +public static class Rectangle { +private String string; + +@ConstructorProperties({"string"}) +public Rectangle(@JohnzonConverter(FailingConverter.class) final String string) { +fail("shouldn't be reached"); +} + +public String getString() { +return string; +} + +public void setString(final String string) { +this.string = string; +} +} + public static class Oval { private String s; @@ -128,5 +184,15 @@ public class MapperBeanConstructorExceptionsTest { public interface Sphere { } +public static class FailingConverter implements Converter { +@Override +public String toString(final T instance) { +throw USER_EXCEPTION; +} +@Override +public T fromString(final String text) { +throw USER_EXCEPTION; +} +} }
[johnzon] branch master updated (62fc2346 -> 877fe134)
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git from 62fc2346 support jakarta classifier for jsonlogic module new 3250243a Catalog of deserialization error messages as they are now new ee3fc2f4 Merge branch 'master' of github.com:apache/johnzon into exception-messages new fd91756d JOHNZON-370 Include class, property, type and json value in mapping exceptions new 7d43052d JOHNZON-372 Entire json value serialized in exception new 70441979 JOHNZON-372 Entire json value serialized in exception new c7b6ce5f JOHNZON-372 Entire json value serialized in exception new 2312ec83 Align wording in "Can't map JSON Object" exception with other exceptions new 11603885 Test cases for all primitive arrays show handling as-is Prior to fixing JOHNZON-371 new e743eed6 JOHNZON-371 NullPointerException thrown when null value present in primitive arrays new 0f6c80eb Add final to static-utility class new c797e133 JOHNZON-376 Mapper API Bean setter user exceptions tests new 21fd9dd3 JOHNZON-376 Mapper API Bean getter user exceptions tests new 9a0f70a2 JOHNZON-382 Diagnose and guide users on invalid bean constructors JOHNZON-376 Mapper API Bean constructor exceptions tests new e49def40 JOHNZON-374 Mapper API Adapter method exception tests new 19fa465a JOHNZON-375 Mapper API Converter methods and constructor exceptions tests new 550bbb1a JOHNZON-381 JsonbAdapter methods and constructor exceptions tests new d8bb51e6 JOHNZON-377 Jsonb bean setter user exceptions test new b0b10cb1 JOHNZON-377 Jsonb bean getter and constructor exception tests new 014889d8 JOHNZON-379 & JOHNZON-380 Jsonb{De}Serializer methods and constructor new 95e8b23a JOHNZON-378 JsonbCreator constructor and factory method exceptions tests new 5e38eda6 Use ExceptionAsserts new 3621f9bd JOHNZON-370 Deserialization Exception message tests for Mapper API new befd7f5a Add Wildcard and GenericArray handling to ExceptionMessages.simpleName new f6e918a1 Prevent recursive wrapping new 877fe134 Merge pull request #91 from dblevins/exception-message-improvements The 916 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../DeserializationExceptionMessagesTest.java | 1540 .../org/apache/johnzon/jsonb/ExceptionAsserts.java | 123 ++ .../johnzon/jsonb/JsonbAdapterExceptionsTest.java | 261 .../jsonb/JsonbBeanConstructorExceptionsTest.java | 133 ++ .../jsonb/JsonbBeanGetterUserExceptionsTest.java | 47 + .../jsonb/JsonbBeanSetterUserExceptionsTest.java | 479 ++ .../johnzon/jsonb/JsonbCreatorExceptionsTest.java | 82 ++ .../jsonb/JsonbSerializerExceptionsTest.java | 212 +++ .../apache/johnzon/jsonb/SnippetMaxLengthTest.java | 24 +- .../apache/johnzon/mapper/ExceptionMessages.java | 108 ++ .../johnzon/mapper/FactoryCreateException.java | 27 +- .../apache/johnzon/mapper/MappingParserImpl.java | 141 +- .../johnzon/mapper/MissingFactoryException.java| 65 + .../johnzon/mapper/SetterMappingException.java | 42 + .../DeserializationExceptionMessagesTest.java | 1539 +++ .../apache/johnzon/mapper/ExceptionAsserts.java| 106 ++ .../mapper/MapperAdapterExceptionsTest.java| 193 +++ .../MapperBeanConstructorExceptionsTest.java | 132 ++ .../mapper/MapperBeanGetterUserExceptionsTest.java | 45 + .../mapper/MapperBeanSetterUserExceptionsTest.java | 478 ++ .../mapper/MapperConverterExceptionsTest.java | 215 +++ .../apache/johnzon/mapper/TypeSimpleNameTest.java | 88 ++ 22 files changed, 6015 insertions(+), 65 deletions(-) create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/DeserializationExceptionMessagesTest.java create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/ExceptionAsserts.java create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbAdapterExceptionsTest.java create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanConstructorExceptionsTest.java create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanGetterUserExceptionsTest.java create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbBeanSetterUserExceptionsTest.java create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbCreatorExceptionsTest.java create mode 100644 johnzon-jsonb/src/test/java/org/apache/johnzon/jsonb/JsonbSerializerExceptionsTest.java create mode 100644 johnzon-mapper/src/main/java/org/apache/johnzon/mapper/ExceptionMessages.java copy