info.freelibrary.iiif.presentation.v3.properties.AbstractI18nStdDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jiiify-presentation-v3 Show documentation
Show all versions of jiiify-presentation-v3 Show documentation
A Java Library for version 3 of the IIIF Presentation API
package info.freelibrary.iiif.presentation.v3.properties;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.ArrayNode;
/**
* An abstract deserializer that our other deserializers can extend.
*
* @param The class being deserialized
*/
abstract class AbstractI18nStdDeserializer extends StdDeserializer {
/**
* The serialVersionUID
for AbstractI18nStdDeserializer.
*/
private static final long serialVersionUID = 433758172553865194L;
/**
* Creates a new deserializer.
*/
AbstractI18nStdDeserializer() {
this(null);
}
/**
* Creates a new deserializer.
*
* @param aClass A class
*/
AbstractI18nStdDeserializer(final Class> aClass) {
super(aClass);
}
/**
* Parses the I18n from a I18nProperty node.
*
* @param aPropertyNode A property that extends the I18nProperty class
* @return An array of I18n
*/
protected I18n[] getI18nStrings(final JsonNode aPropertyNode) {
final Iterator> iterator = aPropertyNode.fields();
final List i18n = new ArrayList<>();
while (iterator.hasNext()) {
final Entry entry = iterator.next();
final JsonNode jsonNode = entry.getValue();
if (jsonNode.isArray()) {
final ArrayNode arrayNode = (ArrayNode) jsonNode;
final List langStrings = new ArrayList<>();
for (int index = 0; index < arrayNode.size(); index++) {
langStrings.add(arrayNode.get(index).asText());
}
i18n.add(new I18n(entry.getKey(), langStrings));
}
}
return i18n.toArray(new I18n[0]);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy