Skip to content

MihajloNesic/json-serialization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JSON Serialization with Java Reflection API

Features

  • @JsonSerializable - Class annotation to mark class as json serializable
  • @JsonElement - Field annotation to mark field as json serializable. Can have an alias and can be marked as required (only for Objects)
  • @JsonInit - Method annotation. The method will execute before the json is constructed

Can serialize

  • primitives and wrapper classes
  • arrays
  • collections (lists, sets)
  • objects
  • maps

Example

@JsonSerializable
public class Student {

    @JsonElement
    private String firstName;

    @JsonElement
    private String lastName;

    @JsonElement(required = false)
    private String middleName;

    public Student(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }
}
Student student = new Student("John", "Doe");
String jsonString = JsonConverter.convertToJson(student);
System.out.println(jsonString);

Output

{"firstName": "John", "lastName": "Doe"}

See tests for full examples

About

Example of a simple library for JSON serialization with Java Reflection API

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy