mercredi 10 avril 2019

How to map a bean (attributes + method) into a java.util.Map?

I have a class with some attributes and domain methods (no getters) that I'd like to map into a java.util.Map. As an example I have the following Foo class:

public class Foo {
private int num;
public String doStuff() { return "num = " + num; }
public Bar doBar() { return new Bar(num); }
public int doZaz(int x) { return x + num; }
public Bar bar;
}

I'd like to have the following map (ignoring attributes with custom types, methods that returns custom types and methods that receive parameters):

{num: 10, doStuff: "num = 10"}

How can I have this?





Aucun commentaire:

Enregistrer un commentaire