LocaleMarshaller implements IJsonMarshaller<Locale> { @Override public Locale toJava(String json) throws JsonUnmarshallingException { Locale locale = null; if(null != json) { try (JsonReader reader = Json.createReader(new StringReader(json))) { JsonObject root = reader.readObject(); locale = new Locale(root.getString(Constants.Message.LANGUAGE), root.getString(Constants.Message.COUNTRY)); } catch(Throwable t) { throw new JsonUnmarshallingException(json); } } return locale; }  @Override String toJson(Locale obj); @Override Locale toJava(String json);  }
@Test public void testToJava() throws Exception { System.out.println("toJava"); String json = "{\"language\":\"fr\",\"country\":\"FR\"}"; Locale result = instance.toJava(json); assertThat(result).isEqualTo(Locale.FRANCE); }
@Test public void testToNullJava() throws Exception { System.out.println("toJava"); Locale result = instance.toJava(null); assertThat(result).isNull(); }
@Test(expected = JsonUnmarshallingException.class) public void testToJavaFail() throws JsonUnmarshallingException { System.out.println("toJava"); String json = "{\"language\":\"fr\"}"; instance.toJava(json); }