[go: nahoru, domu]

Skip to content

CDI interceptor for loading a Json file into a Java class.

License

Notifications You must be signed in to change notification settings

pabloame/loadjsonfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CDI LoadJsonFile - Interceptor

Build Status

A simple CDI interceptor for Java EE 7. It loads json content file into a Java class.

Examples

Loading a json file

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
}

Loading a json file with different name

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
}

How do I get set up?

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>

About

CDI interceptor for loading a Json file into a Java class.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages