https://github.com/kenta-shimizu/jsoncommunicator4java8
jsoncommunicator4java8
https://github.com/kenta-shimizu/jsoncommunicator4java8
java java8 json
Last synced: 11 months ago
JSON representation
jsoncommunicator4java8
- Host: GitHub
- URL: https://github.com/kenta-shimizu/jsoncommunicator4java8
- Owner: kenta-shimizu
- License: apache-2.0
- Created: 2020-07-17T11:28:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-04T14:35:00.000Z (about 5 years ago)
- Last Synced: 2025-02-10T14:52:53.876Z (about 1 year ago)
- Topics: java, java8, json
- Language: Java
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsoncommunicator4java8
## Introduction
- This library proposes communicate method by JSON ([RFC8259](https://tools.ietf.org/html/rfc8259)).
- This library provides automatically parsing JSON <-> POJO(Plain Old Java Object).
- This library requires ([com.shimizukenta.jsonhub](https://github.com/kenta-shimizu/json4java8)) for parsing.
## About communicate method
1. Use `0x00` byte as delimiter. append delimiter after JSON bytes.
## How to use
### Create communicator instance and open, Client or Server
- Open server sample
```java
JsonCommunicator server = JsonCommunicators.openServer(
new InetSocketAddress("127.0.0.1", 10000),
Pojo.class);
```
- Open client sample
```java
JsonCommunicator client = JsonCommunicators.openClient(
new InetSocketAddress("127.0.0.1", 10000),
Pojo.class);
```
If you set `classOfT`, you can receive parsed POJO by `#addPojoReceivedListener`
### Send JSON or POJO
- Send JSON
```java
String json = "{\"name\": \"John\"}";
client.send(json);
```
- Send POJO
```java
Pojo pojo = new Pojo();
pojo.name = "John";
client.send(pojo);
```
### Receive JSON or POJO
- Add listener for receive JSON
```java
client.addJsonReceiveListener((String json) -> {
/* something ... */
});
```
- Add listener for receive parsed POJO
```java
client.addPojoReceiveListener((Pojo pojo) -> {
/* something ... */
});
```
see also [Examples](/src/examples/).