Deserializer: BadRequestAlertException("Unknown property") with test code coverage
This commit is contained in:
@ -163,7 +163,7 @@ public abstract class JsonDeserializerWithAccessFilter<T extends AccessMappings>
|
||||
jsonFieldReader(node, field).readInto(dto);
|
||||
updatingFields.add(field);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException("setting field " + fieldName + " failed", e);
|
||||
throw new BadRequestAlertException("Unknown property", fieldName, "unknownProperty");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -137,9 +137,24 @@ public class ReflectionUtil {
|
||||
T get() throws Exception;
|
||||
}
|
||||
|
||||
public static <T> T unchecked(final ThrowingSupplier<T> supplier) {
|
||||
/**
|
||||
* Catches checked exceptions and wraps these into an unchecked RuntimeException.
|
||||
* <p>
|
||||
* Rationale: Checked exceptions are a controversial Java feature to begin with.
|
||||
* They often mix error handling code into the normal flow of domain rules
|
||||
* or other technical aspects which is not only hard to read but also violates
|
||||
* the Single Responsibility Principle. Often this is even worse for expressions
|
||||
* than it is for statements.
|
||||
* </p>
|
||||
*
|
||||
* @param expression an expresion which returns a T and may throw a checked exception
|
||||
* @param <T> the result type of the expression
|
||||
* @return the result of the expression
|
||||
* @throws RuntimeException which wraps a checked exception thrown by the expression
|
||||
*/
|
||||
public static <T> T unchecked(final ThrowingSupplier<T> expression) {
|
||||
try {
|
||||
return supplier.get();
|
||||
return expression.get();
|
||||
} catch (final Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"error": {
|
||||
"idNotFound": "Technische Datensatz-ID nicht gefunden",
|
||||
"unknownProperty": "Unbekannte Eigenschaft",
|
||||
"shareSubscriptionPositiveQuantity": "Zeichnungen von Geschäftsanteilen erfordern eine positive Stückzahl",
|
||||
"shareCancellationNegativeQuantity": "Kündigungen von Geschäftsanteilen erfordern eine negative Stückzahl",
|
||||
"shareTransactionImmutable": "Transaktionen mit Geschäftsanteilen sind unveränderlich",
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"error": {
|
||||
"idNotFound": "Technical record-ID not found",
|
||||
"unknownProperty": "Unknown Property",
|
||||
"shareSubscriptionPositiveQuantity": "Share subscriptions require a positive quantity",
|
||||
"shareCancellationNegativeQuantity": "Share cancellations require a negative quantity",
|
||||
"shareTransactionImmutable": "Share transactions are immutable",
|
||||
|
Reference in New Issue
Block a user