|
36 | 36 | public class ProblemDetails { |
37 | 37 | public static final String MIME_TYPE = "application/problem+json"; |
38 | 38 | public static final String DEFAULT_TYPE = "about:blank"; |
39 | | - private final URI type; |
40 | | - private final String title; |
41 | | - private final String details; |
42 | | - private final int status; |
43 | | - private final URI instance; |
| 39 | + private URI type; |
| 40 | + private String title; |
| 41 | + private String details; |
| 42 | + private int status; |
| 43 | + private URI instance; |
44 | 44 | private static JsonService jsonService; |
45 | 45 | private static boolean isJsonServiceInitialized; |
46 | 46 |
|
@@ -78,6 +78,36 @@ public URI getInstance() { |
78 | 78 | return this.instance; |
79 | 79 | }; |
80 | 80 |
|
| 81 | + // Default constructor required for JSON serialization, but package private. |
| 82 | + ProblemDetails() { |
| 83 | + /* noop */ |
| 84 | + } |
| 85 | + |
| 86 | + // The setters are package-private so that the class is publicly immutable. |
| 87 | + void setType(URI type) { |
| 88 | + this.type = type; |
| 89 | + } |
| 90 | + |
| 91 | + // The setters are package-private so that the class is publicly immutable. |
| 92 | + void setTitle(String title) { |
| 93 | + this.title = title; |
| 94 | + } |
| 95 | + |
| 96 | + // The setters are package-private so that the class is publicly immutable but can be deserialized from JSON. |
| 97 | + void setDetails(String details) { |
| 98 | + this.details = details; |
| 99 | + } |
| 100 | + |
| 101 | + // The setters are package-private so that the class is publicly immutable but can be deserialized from JSON. |
| 102 | + void setStatus(int status) { |
| 103 | + this.status = status; |
| 104 | + } |
| 105 | + |
| 106 | + // The setters are package-private so that the class is publicly immutable but can be deserialized from JSON. |
| 107 | + void setInstance(URI instance) { |
| 108 | + this.instance = instance; |
| 109 | + } |
| 110 | + |
81 | 111 | private static JsonService getJsonService() { |
82 | 112 | if (ProblemDetails.isJsonServiceInitialized) { |
83 | 113 | return ProblemDetails.jsonService; |
@@ -110,9 +140,9 @@ public static ProblemDetails fromErrorResponse( |
110 | 140 | ); |
111 | 141 | } |
112 | 142 | try { |
113 | | - final ProblemDetailsData pdData = jsonService.fromJson( |
| 143 | + final ProblemDetails pdData = jsonService.fromJson( |
114 | 144 | new ByteArrayInputStream(body), |
115 | | - ProblemDetailsData.class |
| 145 | + ProblemDetails.class |
116 | 146 | ); |
117 | 147 | final URI type = Optional.ofNullable(pdData.getType()) |
118 | 148 | .orElse(URI.create(ProblemDetails.DEFAULT_TYPE)); |
|
0 commit comments