@Test public void deser_PrimitiveGiven_ShouldReturnAsString() { JsonElement json = mock(JsonElement.class); when(json.isJsonNull()).thenReturn(false); when(json.isJsonPrimitive()).thenReturn(true); when(json.getAsString()).thenReturn("whatever"); assertEquals("whatever", deserializer.deserialize(json, null, null)); }
@Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } else if (json.isJsonPrimitive()) { return json.getAsString(); } else if (json.isJsonObject() && json.getAsJsonObject().size() == 0) { return null; } throw new IllegalStateException( "expected a string, null, or an empty object as request body but got" + this.getClass()); }
WebActionRequestBodyAdapter implements JsonDeserializer<String>, JsonSerializer<String> { @Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } else if (json.isJsonPrimitive()) { return json.getAsString(); } else if (json.isJsonObject() && json.getAsJsonObject().size() == 0) { return null; } throw new IllegalStateException( "expected a string, null, or an empty object as request body but got" + this.getClass()); } }
WebActionRequestBodyAdapter implements JsonDeserializer<String>, JsonSerializer<String> { @Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } else if (json.isJsonPrimitive()) { return json.getAsString(); } else if (json.isJsonObject() && json.getAsJsonObject().size() == 0) { return null; } throw new IllegalStateException( "expected a string, null, or an empty object as request body but got" + this.getClass()); }  }
WebActionRequestBodyAdapter implements JsonDeserializer<String>, JsonSerializer<String> { @Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } else if (json.isJsonPrimitive()) { return json.getAsString(); } else if (json.isJsonObject() && json.getAsJsonObject().size() == 0) { return null; } throw new IllegalStateException( "expected a string, null, or an empty object as request body but got" + this.getClass()); }  @Override String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context); @Override JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context); }
WebActionRequestBodyAdapter implements JsonDeserializer<String>, JsonSerializer<String> { @Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } else if (json.isJsonPrimitive()) { return json.getAsString(); } else if (json.isJsonObject() && json.getAsJsonObject().size() == 0) { return null; } throw new IllegalStateException( "expected a string, null, or an empty object as request body but got" + this.getClass()); }  @Override String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context); @Override JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context);  }