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

nl.openweb.structured.data.utils.StructuredDataUtils Maven / Gradle / Ivy

package nl.openweb.structured.data.utils;


import java.util.Optional;

import org.apache.commons.lang3.StringUtils;

import nl.openweb.structured.data.processing.StructuredDataProcessor;
import nl.openweb.structured.data.schema.entities.StructuredData;
import nl.openweb.structured.data.schema.mapping.StructuredDataMapper;

public class StructuredDataUtils {

    private StructuredDataUtils() {
        // private constructor
    }


    public static  H getStructuredDataFor(T bean, Class clazz) {
        return getStructuredDataUsingMapperByNameFor(null, bean, clazz);
    }


    @SuppressWarnings("unchecked")
    public static  H getStructuredDataUsingMapperByNameFor(String name, T bean, Class clazz) {
        H result = null;
        Optional mapper = StringUtils.isNotBlank(name) ? StructuredDataProcessor.get().getMapperByName(name)
                : StructuredDataProcessor.get().getMapperFor(bean);
        if (mapper.isPresent() && bean != null) {
            StructuredData structuredData = mapper.get().transform(bean);
            if (structuredData != null && structuredData.getClass().isAssignableFrom(clazz)) {
                result = (H) structuredData;
            }
        }
        return result;
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy