fr.whimtrip.ext.jwhthtmltopojo.impl.ReplacerDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whimtrip-ext-htmltopojo Show documentation
Show all versions of whimtrip-ext-htmltopojo Show documentation
Fully featured highly pluggable and customizable Java html to pojo reflection converter
package fr.whimtrip.ext.jwhthtmltopojo.impl;
import fr.whimtrip.core.util.exception.ObjectCreationException;
import fr.whimtrip.ext.jwhthtmltopojo.annotation.ReplaceWith;
import fr.whimtrip.ext.jwhthtmltopojo.annotation.Selector;
import fr.whimtrip.ext.jwhthtmltopojo.intrf.HtmlDeserializer;
import java.lang.reflect.Field;
/**
*
* Part of project jwht-htmltopojo
*
* This implementation provided out of the box will replace any valid
* regex pattern matched with another static string provided on top of
* the corresponding field with an {@link ReplaceWith} annotation.
*
* @author Louis-wht
* @since 1.0.0
*/
public class ReplacerDeserializer implements HtmlDeserializer {
private ReplaceWith replaceWith;
/**
* {@inheritDoc}
*/
@Override
public void init(Field field, Object parentObject, Selector selector) throws ObjectCreationException {
replaceWith = field.getAnnotation(ReplaceWith.class);
if(replaceWith == null)
throw new ObjectCreationException(field, this.getClass(), ReplaceWith.class);
}
/**
* {@inheritDoc}
*/
@Override
public String deserializePreConversion(String value) {
return value.replaceAll(replaceWith.value(), replaceWith.with());
}
/**
* {@inheritDoc}
*/
@Override
public String deserializePostConversion(String value) {
return value.replaceAll(replaceWith.value(), replaceWith.with());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy