Test for excludeFieldsWithModifiers().

Fixes issue 324.
This commit is contained in:
Jesse Wilson 2011-12-29 07:17:36 +00:00
parent 740d03ef0e
commit 6d2cf4a853

View File

@ -16,6 +16,7 @@
package com.google.gson;
import java.lang.reflect.Modifier;
import junit.framework.TestCase;
/**
@ -30,4 +31,29 @@ public class GsonBuilderTest extends TestCase {
builder.create();
builder.create();
}
public void testExcludeFieldsWithModifiers() {
Gson gson = new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.VOLATILE, Modifier.PRIVATE)
.create();
assertEquals("{\"d\":\"d\"}", gson.toJson(new HasModifiers()));
}
static class HasModifiers {
private String a = "a";
volatile String b = "b";
private volatile String c = "c";
String d = "d";
}
public void testTransientFieldExclusion() {
Gson gson = new GsonBuilder()
.excludeFieldsWithModifiers()
.create();
assertEquals("{\"a\":\"a\"}", gson.toJson(new HasTransients()));
}
static class HasTransients {
transient String a = "a";
}
}