### Question:
JsonObjectToStringDeserializer extends StdScalarDeserializer<String> { @Override public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { if (!JsonToken.START_OBJECT.equals(jp.getCurrentToken()) && !JsonToken.START_ARRAY.equals(jp.getCurrentToken())) { throw new JsonParseException("tag value is not a json object or array", jp.getCurrentLocation()); } return jp.readValueAsTree().toString(); } JsonObjectToStringDeserializer(); @Override String deserialize(JsonParser jp, DeserializationContext ctxt);  }### Answer:
@Test(expected = JsonParseException.class) public void deserialize_NotJsonObject() throws JsonProcessingException, IOException { when(jsonParser.getCurrentToken()).thenReturn(JsonToken.VALUE_STRING); deserializer.deserialize(jsonParser, dContext); }
@Test public void deserialize() throws JsonProcessingException, IOException { TreeNode deserializedTreeNode = Mockito.mock(TreeNode.class); String deserializedValue = "DESERIALIZED"; when(jsonParser.getCurrentToken()).thenReturn(JsonToken.START_OBJECT); when(jsonParser.readValueAsTree()).thenReturn(deserializedTreeNode); when(deserializedTreeNode.toString()).thenReturn(deserializedValue); String deserializedRetValue = deserializer.deserialize(jsonParser, dContext); assertEquals(deserializedValue, deserializedRetValue); }