jeudi 21 novembre 2019

Generate Java Code ( New Statement + Setters + Getters) or Builder from In-Memory Object

Introduction

I'd like to generate a text with Java code (only constructors, and setters) that re-create some of the java objects in memory. An alternative would be to also use a Java Builder.

I realize that a possible solution would be to navigate the graph using reflection, and write to a file.

Why do I want this?

I want to record HTTP post command request bodies. I want to instantiate Java Objects by reading the JSON bodies. I want to be able to use these to replay commands.

However, since we change the Java classes sometimes, I don't want to actually store the test commands as JSON's. I want JAVA code that would generate the Java In-Memory Objects.

So that if we rename a field in the IDE, the setter and getter would automatically be changed.

Any options?





Aucun commentaire:

Enregistrer un commentaire