GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - yocto/yoclib-jsonrpc-java: This yocLibrary enables your project to encode and decode JSON-RPC messages in Java.

BranchesTags
Open more actions menu

Latest commit

 

History

29 Commits
29 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
pom.xml
pom.xml
 
 

Repository files navigation

yocLib - JSON-RPC (Java)

This yocLibrary enables your project to encode and decode JSON-RPC messages in Java.

Status

Maven Central Version Maven Central Snapshot Version Java CI with Maven codecov

Installation

<dependency>
	<groupId>com.yocto</groupId>
	<artifactId>yoclib-jsonrpc</artifactId>
	<version>1.0.2</version>
</dependency>

Use

Serialization

import com.yocto.yoclib.jsonrpc.JSONRPCException;
import com.yocto.yoclib.jsonrpc.Message;

import org.json.JSONArray;
import org.json.JSONObject;

Message message = Message.createRequestMessageV1(123,"getInfo",new JSONArray().put("payments")); // Create request (version 1.0)
Message message = Message.createNotificationMessageV1("notificationEvent",new JSONArray().put("payed")); // Create notification (version 1.0)
Message message = Message.createResponseMessageV1(123,new JSONObject().put("payments",new JSONArray().put("$10.12").put("$23.45").put("$12.34"))); // Create response (version 1.0)

Object object = message.toObject();

try{
    String json = Message.encodeJSON(object);
}catch(JSONRPCException e){
    //Handle encoding exception
}

Deserialization

import com.yocto.yoclib.jsonrpc.JSONRPCException;
import com.yocto.yoclib.jsonrpc.Message;

import java.util.Scanner;

import org.json.JSONArray;
import org.json.JSONObject;

Scanner scanner = new Scanner(System.in);

String json = scanner.nextLine(); // Get request body

try{
    Object object = Message.decodeJSON(json);
}catch(JSONRPCException e){
    //Handle decoding exception
}

if(Message.isBatch(object)){
    JSONArray arr = (JSONArray) object;
    for(Object element : arr.toList()){
        try{
            Message message = Message.parse(element);
        }catch(JSONRPCException e){
            //Handle message exception
        }
    }
}else{
    try{
        Message message = Message.parse(object);
    }catch(JSONRPCException e){
        //Handle message exception
    }
}

About

This yocLibrary enables your project to encode and decode JSON-RPC messages in Java.

Resources

Readme
GPL-3.0 license
Activity
Custom properties

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.