All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.vpro.domain.JsonProperties Maven / Gradle / Ivy

Go to download

Several domains like 'media', pages' and 'subtitles' in the POMS system share some common properties which are collected here

There is a newer version: 8.3.1
Show newest version
package nl.vpro.domain;

import javax.xml.bind.annotation.XmlEnumValue;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * An enum can be made to extend this, which indicates that an extra method will be present {@link #getXmlValue()} which
 * will be the {@link XmlEnumValue} of the enum value.
 * 

* Normally this would be {@link Enum#name()}}, but sometimes this is overriden, via the said annotation, and you need programmatic access to it. * * @author Michiel Meeuwissen * @since 8.0 */ public interface JsonProperties { default String getJsonPropertyValue() { if (this instanceof Enum) { Class enumClass = getClass(); String name = ((Enum) this).name(); try { JsonProperty jsonValue = enumClass.getField(name).getAnnotation(JsonProperty.class); return jsonValue.value(); } catch (NoSuchFieldException | NullPointerException e) { return name; } } throw new UnsupportedOperationException("Only supported for enums"); } /** * * @since 8.0 */ static & JsonProperties> E valueOfJson(E[] values, String value) { for (E v : values) { if (v.getJsonPropertyValue().equals(value)) { return v; } } throw new IllegalArgumentException("No constant with xml value " + value); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy