All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.streamsets.pipeline.api.ext.json.JsonMapper Maven / Gradle / Ivy

There is a newer version: 6.3.0
Show newest version
/*
 * Copyright contributors to the StreamSets project
 * StreamSets Inc., an IBM Company 2024
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.streamsets.pipeline.api.ext.json;

import java.io.IOException;
import java.util.Map;

/**
 * Facade for a bidirectional Json-Object mapper.
 */
public interface JsonMapper {

  String SERVICE_KEY = "com.streamsets.pipeline.api.ext.json.JsonMapper";

  String SERVICE_FOR_OFFSETS_KEY = "com.streamsets.pipeline.api.ext.json.JsonMapperForOffsets";

  String SERVICE_FOR_KAITAI_KEY = "com.streamsets.pipeline.api.ext.json.JsonMapperForKaitai";

  /**
   * Serializes and object to a string.
   *
   * @param value the object to serialize.
   * @return the serialized string.
   * @throws IOException
   */
  String writeValueAsString(Object value) throws IOException;

  /**
   * Serializes and object to a string, using optional runtime parameters.
   *
   * @param value the object to serialize.
   * @param parameters the runtime parameters to use.
   * @return the serialized string.
   * @throws IOException
   */
  String writeValueAsString(Object value, Map parameters) throws IOException;


  /**
   * Serializes and array of bytes to a string.
   *
   * @param value the object to serialize.
   * @return the serialized string.
   * @throws IOException
   */
  byte[] writeValueAsBytes(Object value) throws IOException;

  /**
   * Serializes and array of bytes to a string, using optional runtime parameters.
   *
   * @param value the object to serialize.
   * @param parameters the runtime parameters to use.
   * @return the serialized string.
   * @throws IOException
   */
  byte[] writeValueAsBytes(Object value, Map parameters) throws IOException;

  /**
   * Deserializes a string onto an object.
   *
   * @param content the string to deserialize.
   * @param valueType The class type to use to deserialize.
   * @param  The deserialized object.
   * @return
   * @throws IOException
   */
  T readValue(String content, Class valueType) throws IOException;

  /**
   * Deserializes a string onto an object, using optional runtime parameters.
   *
   * @param content the string to deserialize.
   * @param valueType The class type to use to deserialize.
   * @param parameters the runtime parameters to use.
   * @param  The deserialized object.
   * @return
   * @throws IOException
   */
  T readValue(String content, Class valueType, Map parameters) throws IOException;


  /**
   * Deserializes an array of bytes onto an object.
   *
   * @param content the array of bytes to deserialize.
   * @param valueType The class type to use to deserialize.
   * @param  The deserialized object.
   * @return
   * @throws IOException
   */
  T readValue(byte[] content, Class valueType) throws IOException;

  /**
   * Deserializes an array of bytes onto an object, using optional runtime parameters.
   *
   * @param content the string to deserialize.
   * @param valueType The class type to use to deserialize.
   * @param parameters the runtime parameters to use.
   * @param  The deserialized object.
   * @return
   * @throws IOException
   */
  T readValue(byte[] content, Class valueType, Map parameters) throws IOException;

  /**
   * Converts an object of given value, into instance of given value type
   *
   * @param fromValue the object to convert.
   * @param toValueType The class type to use to convert.
   * @return the converted java object of toValueType type.
   */
  T convertValue(Object fromValue, Class toValueType) throws IllegalArgumentException;

  /**
   * Produces a model (JSON tree) from a string, ready to traverse, investigate and manipulate.
   *
   * @param content the string to load.
   * @return the tree model.
   * @throws IOException
   */
  JsonModel loadValue(String content) throws IOException;

  /**
   * Produces a model (JSON tree) from an array of bytes, ready to traverse, investigate and manipulate.
   *
   * @param content the array of bytes to load.
   * @return the tree model.
   * @throws IOException
   */
  JsonModel loadValue(byte[] content) throws IOException;

  /**
   * Decoides whether a given string is a valid JSON.
   * @param content the string toi test.
   * @return the result of the test.
   */
  boolean isValidJson(String content);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy