55import com .google .gson .Gson ;
66import com .google .gson .GsonBuilder ;
77import com .google .gson .annotations .Expose ;
8+ import org .javawebstack .abstractdata .mapper .Mapper ;
89import org .javawebstack .abstractdata .util .GsonAbstractDataAdapter ;
910
1011public class AbstractMapper {
1112
13+ // This allows
14+ public static boolean enableExperimentalMapper = false ;
15+
1216 private Gson gson ;
17+ private final Mapper mapper = new Mapper ();
1318 private NamingPolicy namingPolicy = NamingPolicy .NONE ;
1419 private String dateFormat = "yyyy-MM-dd HH:mm:ss" ;
1520 private boolean exposeRequired = false ;
1621
1722 public AbstractMapper setNamingPolicy (NamingPolicy namingPolicy ) {
1823 this .namingPolicy = namingPolicy ;
1924 gson = null ;
25+ mapper .namingPolicy (namingPolicy .getMapperPolicy ());
2026 return this ;
2127 }
2228
@@ -27,6 +33,7 @@ public NamingPolicy getNamingPolicy() {
2733 public AbstractMapper setExposeRequired (boolean exposeRequired ) {
2834 this .exposeRequired = exposeRequired ;
2935 gson = null ;
36+ mapper .requireExpose (exposeRequired );
3037 return this ;
3138 }
3239
@@ -37,6 +44,7 @@ public boolean isExposeRequired() {
3744 public AbstractMapper setDateFormat (String dateFormat ) {
3845 this .dateFormat = dateFormat ;
3946 gson = null ;
47+ mapper .dateFormat (dateFormat );
4048 return this ;
4149 }
4250
@@ -75,12 +83,16 @@ public boolean shouldSkipClass(Class<?> aClass) {
7583 }
7684
7785 public AbstractElement toAbstract (Object object ) {
86+ if (enableExperimentalMapper )
87+ return mapper .map (object );
7888 return AbstractElement .fromJson (gson ().toJsonTree (object ));
7989 }
8090
8191 public <T > T fromAbstract (AbstractElement element , Class <T > type ) {
8292 if (element == null )
8393 return null ;
94+ if (enableExperimentalMapper )
95+ return mapper .map (element , type );
8496 return gson ().fromJson (element .toJson (), type );
8597 }
8698
0 commit comments