Skip to content

Commit 0ce226b

Browse files
authored
feat(oaf-validation-exception): added throwables oneof/anyof validation failures (#70)
- Addition of OneOfValidationException class extending IOException - Addition of AnyOfValidationException class extending IOException - Added Unit tests for the newly created exceptions coverage - Added support of setting type in TypeCombinatorCase annotation to determine the encapsulated type in Container
1 parent 2bda2be commit 0ce226b

7 files changed

Lines changed: 620 additions & 502 deletions

File tree

src/main/java/io/apimatic/core/annotations/TypeCombinator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.annotation.Retention;
55
import java.lang.annotation.RetentionPolicy;
66
import java.lang.annotation.Target;
7+
78
import com.fasterxml.jackson.databind.JsonSerializer;
89

910
/**
@@ -13,6 +14,11 @@ public interface TypeCombinator {
1314
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
1415
@Retention(RetentionPolicy.RUNTIME)
1516
@interface TypeCombinatorCase {
17+
/**
18+
* Java type of the object wrapped in the annotated TypeCombinator container.
19+
* @return String encoded java type of the wrapped object
20+
*/
21+
String type() default "";
1622
}
1723

1824
@Retention(RetentionPolicy.RUNTIME)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.apimatic.core.types;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
import com.fasterxml.jackson.databind.JsonNode;
6+
7+
/**
8+
* This is the base class for all exceptions that represent an error response from the server.
9+
*/
10+
public class AnyOfValidationException extends IOException {
11+
12+
/**
13+
* UID for serialization.
14+
*/
15+
private static final long serialVersionUID = 1214174253911720228L;
16+
17+
/**
18+
* Initialization constructor.
19+
* @param types List on unMapped types
20+
* @param json Value that was not mapped by the above types
21+
*/
22+
public AnyOfValidationException(final List<String> types, final JsonNode json) {
23+
super("We could not match any acceptable type from "
24+
+ String.join(", ", types) + " on: " + json);
25+
}
26+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.apimatic.core.types;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
import com.fasterxml.jackson.databind.JsonNode;
6+
7+
/**
8+
* This is the base class for all exceptions that represent an error response from the server.
9+
*/
10+
public class OneOfValidationException extends IOException {
11+
12+
/**
13+
* UID for serialization.
14+
*/
15+
private static final long serialVersionUID = 6424174253911720228L;
16+
17+
/**
18+
* Initialization constructor.
19+
* @param type1 The first type that was mapped on jsonNode
20+
* @param type2 The second type that also got mapped on jsonNode
21+
* @param json Value that was mapped by the above two types
22+
*/
23+
public OneOfValidationException(final String type1, final String type2, final JsonNode json) {
24+
super("There are more than one matching types i.e. "
25+
+ type1 + " and " + type2 + " on: " + json);
26+
}
27+
28+
/**
29+
* Initialization constructor.
30+
* @param types List on unMapped types
31+
* @param json Value that was not mapped by the above types
32+
*/
33+
public OneOfValidationException(final List<String> types, final JsonNode json) {
34+
super("We could not match any acceptable type from "
35+
+ String.join(", ", types) + " on: " + json);
36+
}
37+
}

0 commit comments

Comments
 (0)