github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgRpc/kmgRpcJava/java/src/com/google/gson/LongSerializationPolicy.java (about)

     1  /*
     2   * Copyright (C) 2009 Google Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   * http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package com.google.gson;
    18  
    19  /**
    20   * Defines the expected format for a {@code long} or {@code Long} type when its serialized.
    21   *
    22   * @since 1.3
    23   *
    24   * @author Inderjeet Singh
    25   * @author Joel Leitch
    26   */
    27  public enum LongSerializationPolicy {
    28    /**
    29     * This is the "default" serialization policy that will output a {@code long} object as a JSON
    30     * number.  For example, assume an object has a long field named "f" then the serialized output
    31     * would be:
    32     * {@code {"f":123}}.
    33     */
    34    DEFAULT() {
    35      public JsonElement serialize(Long value) {
    36        return new JsonPrimitive(value);
    37      }
    38    },
    39    
    40    /**
    41     * Serializes a long value as a quoted string.  For example, assume an object has a long field 
    42     * named "f" then the serialized output would be:
    43     * {@code {"f":"123"}}.
    44     */
    45    STRING() {
    46      public JsonElement serialize(Long value) {
    47        return new JsonPrimitive(String.valueOf(value));
    48      }
    49    };
    50    
    51    /**
    52     * Serialize this {@code value} using this serialization policy.
    53     *
    54     * @param value the long value to be serialized into a {@link JsonElement}
    55     * @return the serialized version of {@code value}
    56     */
    57    public abstract JsonElement serialize(Long value);
    58  }