Class Bin2Json

java.lang.Object
org.openhab.core.io.bin2json.Bin2Json

@NonNullByDefault public class Bin2Json extends Object
This class converts binary data to JSON format. Parser rules follows Java Binary Block Parser syntax.

See details from https://github.com/raydac/java-binary-block-parser

Usage example:

 
 JsonObject json = new Bin2Json("byte a; byte b; ubyte c;").convert("03FAFF");
 json.toString() = {"a":3,"b":-6,"c":255}
 
 
Author:
Pauli Anttila - Initial contribution
  • Constructor Details

  • Method Details

    • convert

      public com.google.gson.JsonObject convert(String hexString) throws ConversionException
      Convert String in hexadecimal string format to JSON object.
      Parameters:
      hexString - Data in hexadecimal string format. Example data: 03FAFF.
      Returns:
      Gson JsonObject.
      Throws:
      ConversionException - if an error occurs during conversion.
    • convert

      public com.google.gson.JsonObject convert(byte[] data) throws ConversionException
      Convert byte array to JSON object.
      Parameters:
      data - Data in byte array format.
      Returns:
      Gson JsonObject.
      Throws:
      ConversionException - if an error occurs during conversion.
    • convert

      public com.google.gson.JsonObject convert(InputStream inputStream) throws ConversionException
      Convert data from InputStream to JSON object.
      Parameters:
      inputStream - input stream where converted data is read.
      Returns:
      Gson JsonObject.
      Throws:
      ConversionException - if an error occurs during conversion.