Skip to content

Commit bc1a22b

Browse files
BAEL-2412
Remove custom serializer and deserializer for converting byte into a string of bits.
1 parent e3b6986 commit bc1a22b

1 file changed

Lines changed: 0 additions & 53 deletions

File tree

gson/src/test/java/org/baeldung/gson/primitives/UnitTest.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,6 @@ public class UnitTest {
5252
// @formatter:on
5353
}
5454

55-
@Test public void toJsonByteToBitString() {
56-
GsonBuilder builder = new GsonBuilder();
57-
builder.registerTypeAdapter(ByteExample.class,
58-
new GsonBitStringSerializer());
59-
60-
Gson gson = builder.create();
61-
ByteExample model = new ByteExample();
62-
model.value = (byte) 0b1111;
63-
64-
assertEquals("{\"value\":\"1111\"}", gson.toJson(model));
65-
}
66-
67-
@Test public void fromJsonByteFromBitString() {
68-
String json = "{\"value\": \"1111\"}";
69-
GsonBuilder gsonBuilder = new GsonBuilder();
70-
gsonBuilder.registerTypeAdapter(ByteExample.class,
71-
new GsonBitStringDeserializer());
72-
73-
Gson gson = gsonBuilder.create();
74-
75-
ByteExample model = gson.fromJson(json, ByteExample.class);
76-
77-
assertEquals(15, model.value);
78-
}
79-
8055
@Test public void fromJsonPrecissionMismatch() {
8156
String json = "{\"value\": 12.123456789123456}";
8257
Gson gson = new Gson();
@@ -212,34 +187,6 @@ public class UnitTest {
212187
}
213188

214189
// @formatter:off
215-
static class GsonBitStringDeserializer implements JsonDeserializer<ByteExample> {
216-
@Override public ByteExample deserialize(
217-
JsonElement jsonElement,
218-
Type type,
219-
JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
220-
221-
ByteExample byteExample = new ByteExample();
222-
byteExample.value = (byte) Integer.parseInt(
223-
jsonElement.getAsJsonObject()
224-
.getAsJsonPrimitive("value")
225-
.getAsString()
226-
, 2);
227-
return byteExample;
228-
}
229-
}
230-
231-
static class GsonBitStringSerializer implements JsonSerializer<ByteExample> {
232-
@Override public JsonElement serialize(
233-
ByteExample model,
234-
Type type,
235-
JsonSerializationContext jsonSerializationContext) {
236-
237-
JsonObject jsonObject = new JsonObject();
238-
jsonObject.addProperty("value", Integer.toBinaryString(model.value));
239-
return jsonObject;
240-
}
241-
}
242-
243190
static class BooleanAs2ValueIntegerDeserializer implements JsonDeserializer<BooleanExample> {
244191
@Override public BooleanExample deserialize(
245192
JsonElement jsonElement,

0 commit comments

Comments
 (0)