A simple CDI interceptor for Java EE 7. It loads json content file into a Java class.
A java class MyDummyClass
annotated with @LoadJsonFile
@Singleton
@LoadJsonFile
public static class MyDummyClass {
private String name;
private int age;
private boolean active;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean isActive() {
return active;
}
}
it will be created with the information stored in MyDummyClass.json
file
{
"name": "Name",
"age": "29",
"active": false
}
In case your json file is named differently to your java class you can specify the name in the annotation.
@Singleton
@LoadJsonFile(fileName = "config.json")
public static class MyDummyClass {
private String name;
private int age;
private boolean active;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public boolean isActive() {
return active;
}
}
and it will be created with the information stored in config.json
{
"name": "Name",
"age": "29",
"active": false
}
Fork this repository and build it. Once is done, add the dependency to your pom.xml project.
<dependency>
<groupId>com.pam.loadjsonfile</groupId>
<artifactId>loadjsonfile</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>