Class NJsonDocUtils

java.lang.Object
gov.nasa.pds.registry.common.util.json.NJsonDocUtils

public class NJsonDocUtils extends Object
Utility class to write NJSON (new-line delimited JSON) documents.
Author:
karpenko
  • Constructor Details

    • NJsonDocUtils

      public NJsonDocUtils()
  • Method Details

    • createPKJson

      public static String createPKJson(String id) throws Exception
      Create primary key JSON (first line in NJSON record)
      Parameters:
      id - primary key
      Returns:
      primary key JSON
      Throws:
      Exception - Generic exception
    • writePK

      public static void writePK(Writer writer, String id) throws Exception
      Write primary key (first line in NJSON record)
      Parameters:
      writer - Generic writer
      id - primary key
      Throws:
      Exception - Generic exception
    • writeField

      public static void writeField(com.google.gson.stream.JsonWriter jw, String key, String value) throws Exception
      Write a field.
      Parameters:
      jw - JSON writer
      key - a key / field name
      value - a value
      Throws:
      Exception - Generic exception
    • writeField

      public static void writeField(com.google.gson.stream.JsonWriter jw, String key, long value) throws Exception
      Write a field.
      Parameters:
      jw - JSON writer
      key - a key / field name
      value - a value
      Throws:
      Exception - Generic exception
    • writeField

      public static void writeField(com.google.gson.stream.JsonWriter jw, String key, float value) throws Exception
      Write a field.
      Parameters:
      jw - JSON writer
      key - a key / field name
      value - a value
      Throws:
      Exception - Generic exception
    • writeField

      public static void writeField(com.google.gson.stream.JsonWriter jw, String key, Collection<String> values) throws Exception
      Write a field.
      Parameters:
      jw - JSON writer
      key - a key / field name
      values - collection of values
      Throws:
      Exception - Generic exception
    • writeArray

      public static void writeArray(com.google.gson.stream.JsonWriter jw, String key, Collection<String> values) throws Exception
      Write multivalued field as an array
      Parameters:
      jw - JSON writer
      key - key / field name
      values - collection of values
      Throws:
      Exception - an exception
    • toEsFieldName

      public static String toEsFieldName(String fieldName)
      Convert registry field name to the valid Elasticsearch field name. (Replace '.' with '/').
      Parameters:
      fieldName - a field name
      Returns:
      valid Elasticsearch field name