https://github.com/mihajlonesic/json-serialization
Example of a simple library for JSON serialization with Java Reflection API
https://github.com/mihajlonesic/json-serialization
annotation java-reflection-api json-serialization
Last synced: 4 months ago
JSON representation
Example of a simple library for JSON serialization with Java Reflection API
- Host: GitHub
- URL: https://github.com/mihajlonesic/json-serialization
- Owner: MihajloNesic
- Created: 2020-04-03T07:12:15.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-07T22:17:43.000Z (about 4 years ago)
- Last Synced: 2025-01-19T13:52:53.922Z (5 months ago)
- Topics: annotation, java-reflection-api, json-serialization
- Language: Java
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## 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
```java
@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;
}
}
``````java
Student student = new Student("John", "Doe");
String jsonString = JsonConverter.convertToJson(student);
System.out.println(jsonString);
```Output
```json
{"firstName": "John", "lastName": "Doe"}
```---
See tests for full examples