Answerer's core is migrated to Hasta,a simple library getting rid of code generation
Answerer is the Celtic mythical sword Fragarach that can attack automatically.
Answerer is just a tool without runtime dependencies and won't disturb your project. With Answerer, you can focus on business logics.
You can use it in existing projects. You can also generate a runnable project with a few configurations. The generated codes are straight-forward, readable and debuggable.
Different from the disposable code generated by IDE, Answerer can keep up with your project continuously. When you modify code, Answerer keeps consistent with your modifications. Not afraid of changing requirements or refactoring!
Since it is so, does Answerer devalue developers? No, developers save time in implementing functionality and have more time to make technologies better!
Answerer is under development but its core is ready for use. Currently its core can wire data and its web extension can generate RESTful services.
- Copy or wire bean properties automatically
- Compile-time duck type check
Call the autowire
method to inject any variable, and it will be wired into returned types automatically (errors will be reported if you injected improper variables). This is more reliable and convenient than Spring.
Your class using autowire
needs to add $UserFunction
to Javadoc, and you can write code like this:
// User has id, email, password, nickname, avatar, brief
// UserView has id, name, avatar, brief
String email="a@a.com", password="1234", nickname="Fraga", avatar="", brief="";
User user = Wirer.autowire(email, password, nickname, avatar, brief);
UserView uv = Wirer.autowire(user);
// "password=" names the value "abcd"
user = Wirer.autowire(uv, email, "password=", "abcd");
// Collections are also OK
List<User> users = Arrays.asList(user, user);
Collection<UserView> uvs = Wirer.autowire(users);
Note that there is a small difference of property name between two classes. What's more, to generate RESTful services it should know the relationship of entity and DTO. So you need to write a few simple configurations in your source folder like this:
// Written in Java which is refactorable (and YAML is welcome in the future)
import sorra.answerer.api.Config;
class MyConfig extends Config {
User user; UserView uv;
{
map(user.nickname, uv.name); // Marks relationship between property names
map(user, uv); // Marks relationship between the entitiy User and the DTO UserView
}
}
If you want to generate RESTful CRUD from a data class, you need to add $EnableRest
to Javadoc and run an update command to generate web controllers.
Currently controllers are overwritten at every time you run update, but you can remove $EnableRest
to avoid updating controllers (while wiring still works).
Requires JDK 8. There's a demo contain entity and DTO.
-
- Build:
./gradlew shadowJar
, the jar is created at build/libs/answerer-0.2-all.jar ; the fileas-config.properties
contains configuration parameters.
- Build:
-
- Generate REST: run
java -jar build/libs/answerer-0.2-all.jar update
in Answerer folder.
- Generate REST: run
-
- Run: run
./gradlew run
in example folder. This builds and starts the example web service.
- Run: run
-
- Verify: create data by
curl -l -H "Content-type: application/json" -X POST -d {} http://localhost:8080/user/new
, and open http://localhost:8080/user/all in browser to see the data.
- Verify: create data by
To generate a new project, run java -jar build/libs/answerer-0.2-all.jar create
in Answerer folder, then write entity or DTO similar to example, and run update.
The built jar accepts command like create
or update
.
Create a file as-config.properties
in your existing project folder, similar to example.
You can add -D parameter like java -jar -Dkey=value answerer.jar update
to override the configurations in as-config.properties
.
Understand user code by syntactical and semantic analysis so that can generate code to cooperate with user code. My Chinese blog explains the technology in detail: https://www.qingjingjie.com/blogs/2
- support constructors with parameters
- TDD friendly design
- Inject any data or relationship automatically, no matter it is from SQL, NoSQL or even Micro-services.
- Lazy loading and Batch loading
- Distributed system solution similar to Micro-services
- A recipes system supporting various third-party frameworks
- SQL DSL
- Corountine
- RAII