Skip to content

Commit 499164d

Browse files
committed
Replace ProblemDetailsData with private setters
1 parent 7ef7937 commit 499164d

File tree

2 files changed

+37
-62
lines changed

2 files changed

+37
-62
lines changed

api/src/main/java/com/inrupt/client/ProblemDetails.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
public class ProblemDetails {
3737
public static final String MIME_TYPE = "application/problem+json";
3838
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;
4444
private static JsonService jsonService;
4545
private static boolean isJsonServiceInitialized;
4646

@@ -78,6 +78,36 @@ public URI getInstance() {
7878
return this.instance;
7979
};
8080

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+
81111
private static JsonService getJsonService() {
82112
if (ProblemDetails.isJsonServiceInitialized) {
83113
return ProblemDetails.jsonService;
@@ -110,9 +140,9 @@ public static ProblemDetails fromErrorResponse(
110140
);
111141
}
112142
try {
113-
final ProblemDetailsData pdData = jsonService.fromJson(
143+
final ProblemDetails pdData = jsonService.fromJson(
114144
new ByteArrayInputStream(body),
115-
ProblemDetailsData.class
145+
ProblemDetails.class
116146
);
117147
final URI type = Optional.ofNullable(pdData.getType())
118148
.orElse(URI.create(ProblemDetails.DEFAULT_TYPE));

api/src/main/java/com/inrupt/client/ProblemDetailsData.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)