doc: ensure error message is documented
diff --git a/src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.java b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.java index d7b1b87..59b9425 100644 --- a/src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.java +++ b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.java
@@ -19,6 +19,8 @@ import jakarta.json.bind.JsonbException; import org.eclipse.yasson.internal.DeserializationContextImpl; +import org.eclipse.yasson.internal.properties.MessageKeys; +import org.eclipse.yasson.internal.properties.Messages; /** * Deserializer of the {@link URI} type. @@ -34,8 +36,7 @@ try { return new URI(value); } catch (URISyntaxException e) { - // Exception will be caught and wrapped - throw new JsonbException("java.net.URI could not parse value " + value, e); + throw new JsonbException(Messages.getMessage(MessageKeys.URI_PARSE_ERROR, value), e); } } }
diff --git a/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java index dbe7980..018448f 100644 --- a/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java +++ b/src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java
@@ -19,6 +19,8 @@ import jakarta.json.bind.JsonbException; import org.eclipse.yasson.internal.DeserializationContextImpl; +import org.eclipse.yasson.internal.properties.MessageKeys; +import org.eclipse.yasson.internal.properties.Messages; /** * Deserializer of the {@link URL} type. @@ -34,8 +36,7 @@ try { return new URL(value); } catch (MalformedURLException e) { - // Exception will be caught and wrapped - throw new JsonbException("java.net.URL could not parse value " + value, e); + throw new JsonbException(Messages.getMessage(MessageKeys.URL_PARSE_ERROR, value), e); } } }
diff --git a/src/main/java/org/eclipse/yasson/internal/properties/MessageKeys.java b/src/main/java/org/eclipse/yasson/internal/properties/MessageKeys.java index d08377c..fde557a 100644 --- a/src/main/java/org/eclipse/yasson/internal/properties/MessageKeys.java +++ b/src/main/java/org/eclipse/yasson/internal/properties/MessageKeys.java
@@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -265,6 +265,14 @@ */ ZONE_PARSE_ERROR("zoneParseError"), /** + * There has been an error parsing a URI value. + */ + URI_PARSE_ERROR("uriParseError"), + /** + * There has been an error parsing a URL value. + */ + URL_PARSE_ERROR("urlParseError"), + /** * {@link JsonbTransient} was not the only annotation on class property. */ JSONB_TRANSIENT_WITH_OTHER_ANNOTATIONS("jsonbTransientWithOtherAnnotations"),
diff --git a/src/main/resources/yasson-messages.properties b/src/main/resources/yasson-messages.properties index 4d22449..a059313 100644 --- a/src/main/resources/yasson-messages.properties +++ b/src/main/resources/yasson-messages.properties
@@ -76,6 +76,8 @@ unknownJsonProperty=Json property {0} can not be mapped to a class {1}. jsonbCreatorMissingProperty=JsonbCreator parameter {0} is missing in json document. zoneParseError=Cannot parse zone from json value: {0} +uriParseError=Cannot parse URI from json value: {0} +urlParseError=Cannot parse URL from json value: {0} jsonbTransientWithOtherAnnotations=JsonbTransient annotation cannot be used with other jsonb annotations on the same property. nonParametrizedType=Type: {0} is not a parametrized type. propertyNameClash=Property {0} clashes with property {1} by read or write name in class {2}.
diff --git a/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.java b/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.java index c9f5991..afd68ba 100644 --- a/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.java +++ b/src/test/java/org/eclipse/yasson/defaultmapping/specific/UnmarshallingUnsupportedTypesTest.java
@@ -230,13 +230,23 @@ @Test public void testMalformedURL() { Type type = new TestTypeToken<ScalarValueWrapper<URL>>(){}.getType(); - assertFail("{\"value\":\"www.oracle.com\"}", type, "value", URL.class); + try { + defaultJsonb.fromJson("{\"value\":\"www.oracle.com\"}", type); + fail("Expected to catch JsonbException but did not"); + } catch (JsonbException e) { + assertTrue(e.getMessage().contains("Cannot parse URL") && e.getMessage().contains("www.oracle.com")); + } } - + @Test public void testMalformedURI() { Type type = new TestTypeToken<ScalarValueWrapper<URI>>(){}.getType(); - assertFail("{\"value\":\"www .oracle .com\"}", type, "value", URI.class); + try { + defaultJsonb.fromJson("{\"value\":\"www .oracle .com\"}", type); + fail("Expected to catch JsonbException but did not"); + } catch (JsonbException e) { + assertTrue(e.getMessage().contains("Cannot parse URI") && e.getMessage().contains("www .oracle .com")); + } } private void assertFail(String json, Type type, String failureProperty, Class<?> failurePropertyClass) {