Class DataFieldAdapter

java.lang.Object
com.google.gson.TypeAdapter<Long>
org.eclipse.mosaic.lib.util.gson.DataFieldAdapter

public class DataFieldAdapter extends com.google.gson.TypeAdapter<Long>
Adapter for JSON fields which translates values as string representatives to actual long values representing the number of bits, e.g.
for size: "10 Bytes" -> 80, "2kbit" -> 2000
for bandwidth: "10 MBps km/h" -> 80000000, "5 kbps" -> 5000

Note: using "b" or "B" is a difference, as former stands for bits and later for bytes.

Usage:

  @JsonAdapter(DataFieldAdapter.Size.class)
  public long size;

 
  • Field Details

  • Method Details

    • write

      public void write(com.google.gson.stream.JsonWriter out, Long param) throws IOException
      Specified by:
      write in class com.google.gson.TypeAdapter<Long>
      Throws:
      IOException
    • read

      public Long read(com.google.gson.stream.JsonReader in) throws IOException
      Specified by:
      read in class com.google.gson.TypeAdapter<Long>
      Throws:
      IOException