@Nullable public LocalizedString getFieldAsLocalizedString(final String name) { return getField(name, LocalizedString.typeReference()); }
@Override @Nullable public LocalizedString getFieldAsLocalizedString(final String name) { return getField(name, LocalizedString.typeReference()); }
@Override @Nullable public LocalizedString getFieldAsLocalizedString(final String name) { return getField(name, LocalizedString.typeReference()); }
static AttributeAccess<LocalizedString> ofLocalizedString() { return AttributeAccessImpl.ofPrimitive(LocalizedString.typeReference(), LocalizedStringAttributeType.class); }
static AttributeAccess<LocalizedString> ofLocalizedString() { return AttributeAccessImpl.ofPrimitive(LocalizedString.typeReference(), LocalizedStringAttributeType.class); }
static AttributeAccess<LocalizedString> ofLocalizedString() { return AttributeAccessImpl.ofPrimitive(LocalizedString.typeReference(), LocalizedStringAttributeType.class); }
@Test public void exceptionHandling() throws Exception { final String brokenJsonString = "{\"de\":\",]]]]"; assertThatThrownBy(() -> SphereJsonUtils.readObject(brokenJsonString, LocalizedString.typeReference())) .isInstanceOf(JsonException.class); }
@Test public void readObjectFromJsonNode() throws Exception { final ObjectNode jsonNode = SphereJsonUtils.newObjectNode(); jsonNode.put("de", "Hundefutter"); jsonNode.put("en", "dog food"); final LocalizedString actual = SphereJsonUtils.readObject(jsonNode, LocalizedString.typeReference()); assertThat(actual).isEqualTo(LocalizedString.of(ENGLISH, "dog food", GERMAN, "Hundefutter")); }
@Test public void readObjectFromJsonString() throws Exception { final String jsonString = "{\"de\":\"Hundefutter\",\"en\":\"dog food\"}"; final LocalizedString actual = SphereJsonUtils.readObject(jsonString, LocalizedString.typeReference()); assertThat(actual).isEqualTo(LocalizedString.of(ENGLISH, "dog food", GERMAN, "Hundefutter")); }
@Test public void serializeWithFullLocale() { final LocalizedString localizedString = SphereJsonUtils.readObject(FULL_LOCALE_JSON_STRING, LocalizedString.typeReference()); assertThat(localizedString.get(Locale.US)).isEqualTo("kids"); assertThat(localizedString.get(Locale.UK)).isEqualTo("children"); }