29
29
30
30
/**
31
31
* This class helps to deserialize JSON to a sub-class of {@link CommandResponse}. Hereby this class extracts the
32
- * values which are common for all command responses. All remaining required values have to be extracted in
33
- * {@link CommandResponseJsonDeserializer.FactoryMethodFunction#create(org.eclipse.ditto.base.model.common.HttpStatus)}.
34
- * There the actual command response object is created, too.
32
+ * values which are common for all command responses.
35
33
*/
36
34
public final class CommandResponseJsonDeserializer <T extends CommandResponse <?>> {
37
35
38
- @ Nullable private final JsonObject jsonObject ;
39
36
private final String expectedCommandResponseType ;
40
37
private final DeserializationFunction <T > deserializationFunction ;
41
38
42
39
private CommandResponseJsonDeserializer (final CharSequence type ,
43
- @ Nullable final JsonObject jsonObject ,
44
40
final DeserializationFunction <T > deserializationFunction ) {
45
41
46
- this .jsonObject = jsonObject ;
47
42
expectedCommandResponseType = ConditionChecker .checkArgument (checkNotNull (type , "type" ).toString (),
48
43
arg -> !arg .trim ().isEmpty (),
49
44
() -> "The type must not be empty or blank." );
50
45
this .deserializationFunction = deserializationFunction ;
51
46
}
52
47
53
- /**
54
- * Constructs a new {@code CommandResponseJsonDeserializer} object.
55
- *
56
- * @param type the type of the command response.
57
- * @param jsonObject the JSON object to deserialize.
58
- * @throws NullPointerException if any argument is {@code null}.
59
- * @throws IllegalArgumentException if {@code type} is empty or blank.
60
- * @deprecated as of 2.3.0 please use {@link #newInstance(CharSequence, DeserializationFunction)} instead.
61
- */
62
- @ Deprecated
63
- public CommandResponseJsonDeserializer (final String type , final JsonObject jsonObject ) {
64
- this (type , checkJsonObjectNotNull (jsonObject ), null );
65
- }
66
-
67
48
private static JsonObject checkJsonObjectNotNull (@ Nullable final JsonObject jsonObject ) {
68
49
return checkNotNull (jsonObject , "jsonObject" );
69
50
}
70
51
71
- /**
72
- * Constructs a new {@code CommandResponseJsonDeserializer} object.
73
- *
74
- * @param type the type of the target command response of deserialization.
75
- * @param jsonString the JSON string to be deserialized.
76
- * @throws NullPointerException if any argument is {@code null}.
77
- * @throws IllegalArgumentException if {@code type} is empty or blank or if {@code jsonString} is empty.
78
- * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonString} does not contain a valid JSON object.
79
- * @deprecated as of 2.3.0 please use {@link #newInstance(CharSequence, DeserializationFunction)} instead.
80
- */
81
- @ Deprecated
82
- public CommandResponseJsonDeserializer (final String type , final String jsonString ) {
83
- this (type , JsonObject .of (jsonString ));
84
- }
85
-
86
52
/**
87
53
* Returns a new instance of {@code CommandResponseJsonDeserializer}.
88
54
*
@@ -99,33 +65,10 @@ public CommandResponseJsonDeserializer(final String type, final String jsonStrin
99
65
public static <T extends CommandResponse <?>> CommandResponseJsonDeserializer <T > newInstance (final CharSequence type ,
100
66
final DeserializationFunction <T > deserializationFunction ) {
101
67
102
- return new CommandResponseJsonDeserializer (type ,
103
- null ,
68
+ return new CommandResponseJsonDeserializer <>(type ,
104
69
checkNotNull (deserializationFunction , "deserializationFunction" ));
105
70
}
106
71
107
- /**
108
- * Partly deserializes the JSON which was given to this object's constructor. The factory method function which is
109
- * given to this method is responsible for creating the actual {@code CommandResponseType}. This method receives
110
- * the partly deserialized values which can be completed by implementors if further values are required.
111
- *
112
- * @param factoryMethodFunction creates the actual {@code CommandResponseType} object.
113
- * @return the command response.
114
- * @throws NullPointerException if {@code factoryMethodFunction} is {@code null}.
115
- * @throws org.eclipse.ditto.json.JsonParseException if the JSON is invalid or if the command response type
116
- * differs from the expected one.
117
- * @deprecated as of 2.3.0 please use {@link #deserialize(JsonObject, DittoHeaders)} instead.
118
- */
119
- @ Deprecated
120
- public T deserialize (final FactoryMethodFunction <T > factoryMethodFunction ) {
121
- final CommandResponseJsonDeserializer <T > deserializer =
122
- new CommandResponseJsonDeserializer <>(expectedCommandResponseType ,
123
- checkJsonObjectNotNull (jsonObject ),
124
- context -> factoryMethodFunction .create (context .getDeserializedHttpStatus ()));
125
-
126
- return deserializer .deserialize (jsonObject , DittoHeaders .empty ());
127
- }
128
-
129
72
/**
130
73
* Deserializes the specified {@code JsonObject} argument to an instance of {@code CommandResponse}.
131
74
* Any exception that is thrown during deserialization will be subsumed as cause of a {@code JsonParseException}.
@@ -177,28 +120,6 @@ private JsonParseException newJsonParseException(final Exception cause) {
177
120
.build ();
178
121
}
179
122
180
- /**
181
- * Represents a function that accepts three arguments to produce a {@code CommandResponse}. The arguments were
182
- * extracted from a given JSON beforehand.
183
- *
184
- * @param <T> the type of the result of the function.
185
- * @deprecated as of 2.3.0 please use {@link DeserializationFunction} instead.
186
- */
187
- @ Deprecated
188
- @ FunctionalInterface
189
- public interface FactoryMethodFunction <T extends CommandResponse <?>> {
190
-
191
- /**
192
- * Creates a {@code CommandResponse} with the help of the given arguments.
193
- *
194
- * @param httpStatus the HTTP status of the response.
195
- * @return the command response.
196
- * @since 2.0.0
197
- */
198
- T create (HttpStatus httpStatus );
199
-
200
- }
201
-
202
123
/**
203
124
* Function that actually deserializes a {@code CommandResponse} from a provided {@link DeserializationContext}.
204
125
*
0 commit comments