Goland style method impl/Monkey patch experiments in Java.
// 1. define types-class:
public interface Jsonable<T> {
String toJson(T t);
}
// 2. write your POJO:
public final class ObjectB {
private String value;
//getter/setter
}
// 3. implement a method somewhere:
@Implementation(Jsonable.class)
public static String toJson(ObjectB self) {
return String.format("{\"value\": \"%s\"}", self.getValue());
}
// 4. directly call it:
ObjectB b = new ObjectB();
b.setValue("abc")
System.out.println(b.toJson());
mvn install
mvn compile -pl clientapp exec:java
# {"value": "abc"}
See demo.App
in clientapp executed with method toJson
added to ObjectB
mvndebug
+ your IDE's remote JVM debug.
Similar to Project Lombok
Cause Chung cuzfrog@gmail.com