Skip to content

Framework agnostic YAML based serializer for Java.

License

Notifications You must be signed in to change notification settings

webbeta/Serializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webBeta Serializer

Build Status Coverage Status Codacy Badge Scrutinizer Code Quality GitHub license Maven Total alerts Language grade: Java

What is webBeta Serializer?

YML based serializer for Java. Based on JMS serializer https://jmsyst.com/libs/serializer/master/reference/yml_reference

To create a Serializer instance:

Cache cache = new Cache() {
    @Override
    public String get(String key) { return null; }
    
    @Override
    public void set(String key, String content) {}
    
    @Override
    public void remove(String key) {}
};

ConfigurationProvider configurationProvider = new ConfigurationProvider() {
    @Override
    public boolean getBoolean(String key, boolean defaultValue) { return true; }
    
    @Override
    public String getString(String key, String defaultValue) {  return ""; }
};

Environment environment = () -> false;

Serializer serializer = SerializerBuilder.build()
        .withCache(cache)
        .withConfigurationProvider(configurationProvider)
        .withEnvironment(environment)
        .get();

And to add a logger instance:

Logger logger = new Logger() {
    @Override
    public Level getLevel() { return Level.ERROR; }

    @Override
    public void setLevel(Level level) { }

    @Override
    public void error(String message) { }
};

serializer.setLogger(logger);

Quick examples

Class Foo:

package foo.bar;

class Foo {
    
    private String bar = "foobar";
    
    public String getBar() {
        return bar;
    }
    
    public Long getCalc() {
        return 2 + 2;
    }
    
}

Yml file (named foo.bar.Foo.yml):

foo.bar.Foo:
  virtual_properties:
    getCalc:
      serialized_name: calc
      groups: [barGroup]
  properties:
    bar:
      groups: [fooGroup]

Usage:

serializer.serialize(fooInstance, "fooGroup", "barGroup");

// it will return
// {"bar": "foobar", "calc": 4}

License

MIT