1

I would like to generate Json from any object. But I need to modify some values according to its field annotaion. I have already declared annotaion:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Units {

    public Unit value();

}

Enum Unit is declared:

public enum Unit {
    MHz,
    V,
    GB,
    MB,
    b
}

Finally, I would like to modify value according to annotated value. Example:

public class Item {
    String name;
    @Units(Unit.V)
    Integer value;

    // .. getters and setters
}

would be parsed into:

{
    "name": "Ohm",
    "value": "1V"
}

Is there any simple way to do it?

0 Answers0