Tabnine Logo
Gson.toJsonTree
Code IndexAdd Tabnine to your IDE (free)

How to use
toJsonTree
method
in
com.google.gson.Gson

Best Java code snippets using com.google.gson.Gson.toJsonTree (Showing top 20 results out of 2,331)

origin: gocd/gocd

public JsonElement toJSON() {
  return GSON.toJsonTree(this);
}
origin: gocd/gocd

public JsonElement toJSON() {
  return GSON.toJsonTree(this);
}
origin: gocd/gocd

public JsonElement toJSON() {
  return GSON.toJsonTree(this);
}
origin: MovingBlocks/Terasology

  @Override
  public JsonElement getValueAsJson() {
    return GSON.toJsonTree(value);
  }
}
origin: gocd/gocd

public JsonReader jsonReaderFrom(Map map) {
  try {
    return new JsonReader(GSON.toJsonTree(map).getAsJsonObject());
  } catch (Exception e) {
    throw new JsonParseException(e);
  }
}
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = customHg;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRHgMaterial.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = named;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRConfigMaterial.TYPE_NAME));
}
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = customSvn;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRSvnMaterial.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = dependsOnPipeline;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRDependencyMaterial.TYPE_NAME));
}
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingNantTask()
{
  CRTask value = nantWithPath;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is("nant"));
}
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = veryCustomGit;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRGitMaterial.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = pluggableGit;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRPluggableScmMaterial.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingRakeTask()
{
  CRTask value = rakeTask;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is("rake"));
}
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingTask()
{
  CRTask value = curl;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRPluggableTask.TYPE_NAME));
}
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingTasks()
{
  CRTask value = simpleExecWithArgs;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRExecTask.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = customTfs;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRTfsMaterial.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = p4custom;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRP4Material.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingAntTask()
{
  CRTask value = antTask;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is("ant"));
}
@Test
origin: gocd/gocd

@Test
public void shouldAppendTypeFieldWhenSerializingMaterials()
{
  CRMaterial value = packageMaterial;
  JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
  assertThat(jsonObject.get("type").getAsString(), is(CRPackageMaterial.TYPE_NAME));
}
@Test
origin: gocd/gocd

@Test
public void shouldIgnoreWhenJsonHasUnknownElements()
{
  Map<String,T> examples = getExamples();
  for(Map.Entry<String,T> example : examples.entrySet()) {
    T value = example.getValue();
    JsonObject jsonObject = (JsonObject)gson.toJsonTree(value);
    jsonObject.add("extraProperty", new JsonPrimitive("This is not part of message type"));
    String json = gson.toJson(jsonObject);
    T deserializedValue = (T)gson.fromJson(json,value.getClass());
    assertThat(String.format("Example %s - Deserialized value should equal to value before serialization", example.getKey()),
        deserializedValue, is(value));
  }
}
com.google.gsonGsontoJsonTree

Javadoc

This method serializes the specified object into its equivalent representation as a tree of JsonElements. This method should be used when the specified object is not a generic type. This method uses Class#getClass() to get the type for the specified object, but the getClass() loses the generic type information because of the Type Erasure feature of Java. Note that this method works fine if the any of the object fields are of generic type, just the object itself should not be of a generic type. If the object is of generic type, use #toJsonTree(Object,Type) instead.

Popular methods of Gson

  • fromJson
    This method deserializes the specified Json into an object of the specified type. This method is use
  • toJson
    This method serializes the specified object, including those of generic types, into its equivalent J
  • <init>
  • getAdapter
    Returns the type adapter for type.
  • getDelegateAdapter
    This method is used to get an alternate type adapter for the specified type. This is used to access
  • newJsonWriter
    Returns a new JSON writer configured for this GSON and with the non-execute prefix if that is config
  • newJsonReader
    Returns a new JSON reader configured for the settings on this Gson instance.
  • assertFullConsumption
  • doubleAdapter
  • floatAdapter
  • longAdapter
  • fieldNamingStrategy
  • longAdapter,
  • fieldNamingStrategy,
  • toString,
  • atomicLongAdapter,
  • atomicLongArrayAdapter,
  • checkValidFloatingPoint,
  • excluder,
  • newBuilder,
  • fromGson

Popular in Java

  • Creating JSON documents from java classes using gson
  • scheduleAtFixedRate (Timer)
  • onCreateOptionsMenu (Activity)
  • onRequestPermissionsResult (Fragment)
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • Semaphore (java.util.concurrent)
    A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if
  • Notification (javax.management)
  • Top PhpStorm 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