congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
GsonBuilder.setVersion
Code IndexAdd Tabnine to your IDE (free)

How to use
setVersion
method
in
com.google.gson.GsonBuilder

Best Java code snippets using com.google.gson.GsonBuilder.setVersion (Showing top 18 results out of 315)

origin: zstackio/zstack

  public Gson create() {
    //TODO: configuration database
    _gsonBuilder.setVersion(1.7);
    return _gsonBuilder.create();
  }
}
origin: apache/cloudstack

public JsonMessageSerializer() {
  GsonBuilder gsonBuilder = new GsonBuilder();
  gsonBuilder.setVersion(1.5);
  _gson = gsonBuilder.create();
}
origin: apache/cloudstack

try {
  GsonBuilder gb = new GsonBuilder();
  gb.setVersion(1.3);
  Gson gson = gb.create();
origin: apache/cloudstack

static Gson setDefaultGsonConfig(GsonBuilder builder) {
  builder.setVersion(1.5);
  InterfaceTypeAdaptor<DataStoreTO> dsAdaptor = new InterfaceTypeAdaptor<DataStoreTO>();
  builder.registerTypeAdapter(DataStoreTO.class, dsAdaptor);
  InterfaceTypeAdaptor<DataTO> dtAdaptor = new InterfaceTypeAdaptor<DataTO>();
  builder.registerTypeAdapter(DataTO.class, dtAdaptor);
  ArrayTypeAdaptor<Command> cmdAdaptor = new ArrayTypeAdaptor<Command>();
  builder.registerTypeAdapter(Command[].class, cmdAdaptor);
  ArrayTypeAdaptor<Answer> ansAdaptor = new ArrayTypeAdaptor<Answer>();
  builder.registerTypeAdapter(Answer[].class, ansAdaptor);
  builder.registerTypeAdapter(new TypeToken<List<PortConfig>>() {
  }.getType(), new PortConfigListTypeAdaptor());
  builder.registerTypeAdapter(new TypeToken<Pair<Long, Long>>() {
  }.getType(), new NwGroupsCommandTypeAdaptor());
  Gson gson = builder.create();
  dsAdaptor.initGson(gson);
  dtAdaptor.initGson(gson);
  cmdAdaptor.initGson(gson);
  ansAdaptor.initGson(gson);
  return gson;
}
origin: apache/cloudstack

try {
  GsonBuilder gb = new GsonBuilder();
  gb.setVersion(1.3);
  Gson gson = gb.create();
  status = gson.fromJson(cmd.getLoadInfo(), ConsoleProxyStatus.class);
origin: apache/cloudstack

try {
  GsonBuilder gb = new GsonBuilder();
  gb.setVersion(1.3);
  Gson gson = gb.create();
  status = gson.fromJson(answer.getDetails(), ConsoleProxyStatus.class);
origin: MissionCriticalCloud/cosmic

public JsonMessageSerializer() {
  final GsonBuilder gsonBuilder = new GsonBuilder();
  gsonBuilder.setVersion(1.5);
  _gson = gsonBuilder.create();
}
origin: groboclown/p4ic4idea

private Gson buildGson() {
  final GsonBuilder gson = new GsonBuilder();
  gson.setVersion(version.asFloat());
  return gson.create();
}
origin: caelum/vraptor4

@Override
public void version(double versionNumber) {
  getGsonBuilder().setVersion(versionNumber);
}
origin: jruesga/rview

  public static GsonBuilder createGerritGsonBuilder(
      boolean nonExecutable, PlatformAbstractionLayer abstractionLayer) {
    GsonBuilder builder = new GsonBuilder()
        .setVersion(GerritApi.API_VERSION)
        .registerTypeAdapter(Date.class, new GerritUtcDateAdapter())
        .registerTypeAdapter(ServerVersion.class, new GerritServerVersionAdapter())
        .registerTypeAdapter(ApprovalInfo.class, new GerritApprovalInfoAdapter())
        .registerTypeAdapter(Base64Data.class, new GerritBas64Adapter(abstractionLayer))
        .setLenient();
    if (nonExecutable) {
      builder.generateNonExecutableJson();
    }
    return builder;
  }
}
origin: LightSun/data-mediator

private static Object fromJson(String json, Class<?> clazz, int complexType) {
  GsonBuilder builder = new GsonBuilder()
      .setVersion(GlobalSetting.getDefault().getGsonVersion());
origin: apache/fluo

/**
 * Generate JSON format as result of the scan.
 *
 * @since 1.2
 */
private static void generateJson(CellScanner cellScanner, Function<Bytes, String> encoder,
  PrintStream out) throws JsonIOException {
 Gson gson = new GsonBuilder().serializeNulls().setDateFormat(DateFormat.LONG)
   .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).setVersion(1.0)
   .create();
 Map<String, String> json = new LinkedHashMap<>();
 for (RowColumnValue rcv : cellScanner) {
  json.put(FLUO_ROW, encoder.apply(rcv.getRow()));
  json.put(FLUO_COLUMN_FAMILY, encoder.apply(rcv.getColumn().getFamily()));
  json.put(FLUO_COLUMN_QUALIFIER, encoder.apply(rcv.getColumn().getQualifier()));
  json.put(FLUO_COLUMN_VISIBILITY, encoder.apply(rcv.getColumn().getVisibility()));
  json.put(FLUO_VALUE, encoder.apply(rcv.getValue()));
  gson.toJson(json, out);
  out.append("\n");
  if (out.checkError()) {
   break;
  }
 }
 out.flush();
}
origin: me.wuwenbin/template-utils-json

  builder.serializeNulls();
if (version != null)
  builder.setVersion(version.doubleValue());
if (isEmpty(datePattern))
  datePattern = DEFAULT_DATE_PATTERN;
origin: LightSun/data-mediator

/**
 * convert the target object to json. currently support simple object, array , list. SparseArray
 * @param t the object. must have annotation {@linkplain JsonAdapter}
 * @return the json string.
 * @see SparseArray
 */
public static String toJson(Object t) {
  GsonBuilder builder = new GsonBuilder()
      .setVersion(GlobalSetting.getDefault().getGsonVersion());
  if(t instanceof SparseArray){
    SparseArray sa = (SparseArray) t;
    if(sa.size() == 0){
      return "{}";
    }
    Class<?> clazz = sa.valueAt(0).getClass();
   /*  builder.registerTypeAdapter(
        TypeToken.getParameterized(SparseArray.class, clazz).getType(),
        new SparseArrayTypeAdapter<>(TypeHandler.getTypeAdapter(clazz)));*/
    builder.registerTypeAdapter(SparseArray.class,
        new SparseArrayTypeAdapter<>(TypeHandler.getTypeAdapter(clazz)));
  }
  return builder.create().toJson(t);
}
origin: usethesource/rascal

public IString toJSON(IValue value, IBool compact) {
  // System.err.println("hallo");
  IValueAdapter adap = new IValueAdapter(compact.getValue());
  // System.err.println(adap);
  Gson gson = new GsonBuilder()
  .registerTypeAdapter(IValue.class, adap)
  .enableComplexMapKeySerialization()
  .setDateFormat(DateFormat.LONG)
  .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
  .setVersion(1.0)
  .disableHtmlEscaping()  // Bert Lisser
  .create();
  try {
    String json = gson.toJson(value, new TypeToken<IValue>() {}.getType());
    return values.string(json);
  } catch (Exception e) {
    throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
  }
}

origin: usethesource/rascal

public IValue fromJSON(IValue type, IString src, RascalExecutionContext rex) {
  TypeStore store = rex.getTypeStore(); // new TypeStore();
  
  IConstructor type_cons = ((IConstructor) type);
  Type start = tr.valueToType(type_cons, store);
  
  //TypeStore store = ctx.getCurrentEnvt().getStore();
  //Type start = new TypeReifier(ctx.getValueFactory()).valueToType((IConstructor) type, store);
  
  //System.err.println("fromJSON0:"+start);
  Gson gson = new GsonBuilder()
  .enableComplexMapKeySerialization()
  .setDateFormat(DateFormat.LONG)
  .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
  .setVersion(1.0)
  .create();
  //System.err.println("fromJSON1:"+src.getValue());
  Object obj = gson.fromJson(src.getValue(), Object.class);
  //System.err.println("fromJSON2:"+start);
  try {
    return JSONReadingTypeVisitor.read(obj, values, store, start);
  }
  catch (IOException e) {
    throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
  }
}

origin: usethesource/rascal

public IValue fromJSON(IValue type, IString src, IEvaluatorContext ctx) {
  TypeStore store = ctx.getCurrentEnvt().getStore();
  Type start = new TypeReifier(ctx.getValueFactory()).valueToType((IConstructor) type, store);
  Gson gson = new GsonBuilder()
  .enableComplexMapKeySerialization()
  .setDateFormat(DateFormat.LONG)
  .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
  .setVersion(1.0)
  .create();
  Object obj = gson.fromJson(src.getValue(), Object.class);
  try {
    return JSONReadingTypeVisitor.read(obj, values, store, start);
  }
  catch (IOException e) {
    throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
  }
}

origin: LightSun/data-mediator

private static void test2() {
  //gson 还可以根据版本去选择是否序列化/反序列化
  Gson gson = new GsonBuilder().setVersion(2.0).create();
  Car3 car = new Car3();
  car.setMark("AUDI");
  car.setModel(2014); //2,1
  car.setType("DIESEL");
  car.setMaker("AUDI GERMANY");
  car.setCost(55000);
  car.getColors().add("GREY");
  car.getColors().add("BLACK");
  car.getColors().add("WHITE");
  /* Serialize */
  String jsonString = gson.toJson(car);
  System.out.println("Serialized jsonString : " + jsonString);
  /* Deserialize */
  String inputJson = "{\"mark\":\"AUDI\",\"model\":2014,\"type\":\"DIESEL\",\"maker\":\"AUDI Germany\",\"cost\":55000,\"colors\":[\"GRAY\",\"BLACK\",\"WHITE\"]}";
  car = gson.fromJson(inputJson, Car3.class);
  System.out.println("Deserialized Car : " + car);
}
com.google.gsonGsonBuildersetVersion

Javadoc

Configures Gson to enable versioning support.

Popular methods of GsonBuilder

  • create
    Creates a Gson instance based on the current configuration. This method is free of side-effects to t
  • <init>
    Creates a GsonBuilder instance that can be used to build Gson with various configuration settings. G
  • registerTypeAdapter
    Configures Gson for custom serialization or deserialization. This method combines the registration o
  • setPrettyPrinting
    Configures Gson to output Json that fits in a page for pretty printing. This option only affects Jso
  • serializeNulls
    Configure Gson to serialize null fields. By default, Gson omits all fields that are null during seri
  • disableHtmlEscaping
    By default, Gson escapes HTML characters such as < > etc. Use this option to configure Gson to pass-
  • setDateFormat
    Configures Gson to serialize Date objects according to the pattern provided. You can call this metho
  • registerTypeAdapterFactory
    Register a factory for type adapters. Registering a factory is useful when the type adapter needs to
  • setFieldNamingPolicy
    Configures Gson to apply a specific naming policy to an object's field during serialization and dese
  • registerTypeHierarchyAdapter
    Configures Gson for custom serialization or deserialization for an inheritance type hierarchy. This
  • excludeFieldsWithoutExposeAnnotation
    Configures Gson to exclude all fields from consideration for serialization or deserialization that d
  • setExclusionStrategies
    Configures Gson to apply a set of exclusion strategies during both serialization and deserialization
  • excludeFieldsWithoutExposeAnnotation,
  • setExclusionStrategies,
  • enableComplexMapKeySerialization,
  • setLenient,
  • addSerializationExclusionStrategy,
  • excludeFieldsWithModifiers,
  • serializeSpecialFloatingPointValues,
  • setFieldNamingStrategy,
  • addTypeAdaptersForDate

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • getExternalFilesDir (Context)
  • Menu (java.awt)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JFileChooser (javax.swing)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now