本文整理汇总了Java中org.azeckoski.reflectutils.transcoders.JSONTranscoder类的典型用法代码示例。如果您正苦于以下问题:Java JSONTranscoder类的具体用法?Java JSONTranscoder怎么用?Java JSONTranscoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONTranscoder类属于org.azeckoski.reflectutils.transcoders包,在下文中一共展示了JSONTranscoder类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDateEncoding
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
public void testDateEncoding() {
Transcoder transcoder = new JSONTranscoder(false, true, false);
String encoded = null;
Date d = new Date(1255129200000l);
encoded = transcoder.encode(d, "date", null);
assertNotNull(encoded);
assertEquals("1255129200000", encoded);
Timestamp t = new Timestamp(1255129200000l);
encoded = transcoder.encode(t, "date", null);
assertNotNull(encoded);
assertEquals("1255129200000", encoded);
/* sql date is not immutable
java.sql.Date sd = new java.sql.Date(1255129200000l);
encoded = transcoder.encode(sd, "date", null);
assertNotNull(encoded);
assertEquals("1255129200000", encoded);
*/
}
示例2: getTranscoder
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
private Transcoder getTranscoder(String format) {
if (transcoders == null) {
transcoders = new HashMap<String, Transcoder>();
JSONTranscoder jt = new JSONTranscoder(true, true, false);
transcoders.put(jt.getHandledFormat(), jt);
XMLTranscoder xt = new XMLTranscoder(true, true, false, false);
transcoders.put(xt.getHandledFormat(), xt);
HTMLTranscoder ht = new HTMLTranscoder();
transcoders.put(ht.getHandledFormat(), ht);
}
Transcoder transcoder = transcoders.get(format);
if (transcoder == null) {
throw new IllegalArgumentException("Failed to find a transcoder for format, none exists, cannot encode or decode data for format: " + format);
}
return transcoder;
}
示例3: getTranscoder
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
public Transcoder getTranscoder(String format) {
if (transcoders == null) {
transcoders = new HashMap<String, Transcoder>();
JSONTranscoder jt = new JSONTranscoder(true, true, false);
jt.setMaxLevel(entityBrokerManager.getMaxJSONLevel());
transcoders.put(jt.getHandledFormat(), jt);
transcoders.put(Formats.JSONP, jt);
XMLTranscoder xt = new XMLTranscoder(true, true, false, false);
transcoders.put(xt.getHandledFormat(), xt);
HTMLTranscoder ht = new HTMLTranscoder();
transcoders.put(ht.getHandledFormat(), ht);
}
Transcoder transcoder = transcoders.get(format);
if (transcoder == null) {
throw new IllegalArgumentException("Failed to find a transcoder for format, none exists, cannot encode or decode data for format: " + format);
}
return transcoder;
}
示例4: getKalturaBaseEntryAsJSON
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
/**
* The JSONTranscoder doesn't do well with ENUMs and doesn't give us the code we need, so we manually populate a map of the
* values we need.
*
* @param newEntry
* @return JSON representation of the values from the KalturaBaseEntry
*/
private Object getKalturaBaseEntryAsJSON(KalturaBaseEntry kalturaBaseEntry) {
Map<String, Object> map = ReflectUtils.getInstance().getObjectValues(kalturaBaseEntry, FieldsFilter.SERIALIZABLE, false);
for (String key : map.keySet()) {
Object value = map.get(key);
if (value instanceof KalturaEnumAsInt) {
map.put(key, ((KalturaEnumAsInt) value).getHashCode());
} else if (value instanceof KalturaEnumAsString) {
map.put(key, ((KalturaEnumAsString) value).getHashCode());
}
}
return JSONTranscoder.makeJSON(map);
}
示例5: testLoopStoppingJSON
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
public void testLoopStoppingJSON() {
Transcoder transcoder = new JSONTranscoder(true, true, false);
String encoded = null;
TestBaseOne tbo = new TestBaseOne();
encoded = transcoder.encode(tbo, null, null);
int size = encoded.length();
assertNotNull(encoded);
assertTrue(size > 1000);
assertTrue(size < 200000);
}
示例6: testCrazyClassesJSON
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
public void testCrazyClassesJSON() {
TestHibernateLikeBean crazy = new TestHibernateLikeBean();
Transcoder transcoder = new JSONTranscoder(true, true, false);
String encoded = null;
encoded = transcoder.encode(crazy, null, null);
int size = encoded.length();
assertNotNull(encoded);
assertTrue(size > 100);
assertTrue(size < 1000);
}
示例7: testJSONEncodeInvalid
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
public void testJSONEncodeInvalid() {
JSONTranscoder transcoder = new JSONTranscoder();
JsonReader reader = transcoder.new JsonReader();
Map<?,?> map;
Object read;
// invalid (becomes null)
read = reader.read("");
assertNull(read);
read = reader.read(" ");
assertNull(read);
read = reader.read(":");
assertNull(read);
read = reader.read("{");
assertNull(read);
read = reader.read("[");
assertNull(read);
read = reader.read("{\"nonterminating string}");
assertNull(read);
read = reader.read("{{{{");
assertNull(read);
// empty
read = reader.read("{ }");
assertNotNull(read);
assertTrue(read instanceof Map);
read = reader.read("{ \"key\" : \"string\" }");
assertNotNull(read);
assertTrue(read instanceof Map);
map = (Map<?,?>) read;
assertEquals(1, map.size());
map = (Map<?,?>) reader.read("{ \"number\": 12345 }");
assertEquals(12345, map.get("number"));
map = (Map<?,?>) reader.read("{ \"number\": -1.212345 }");
// I think this should be a double really according to the JSON spec
assertEquals(-1.212345f, map.get("number"));
map = (Map<?,?>) reader.read("{ \"object\": { \"key\": 5} }");
assertEquals(5, ((Map<?,?>) map.get("object")).get("key"));
map = (Map<?,?>) reader.read("{ \"key1\": 1, \"key2\": 2 }");
assertEquals(1, map.get("key1"));
assertEquals(2, map.get("key2"));
List<?> list = (List<?>) reader.read("[ 0,1,2,3,4,5 ]");
assertEquals(1, list.get(1));
assertEquals(5, list.get(5));
String rnd = generateString(new Random(),
"abcdefghijklmnopqrstuvwxyz012344567789{}[]'\";;&<>\\!?",
10000000);
reader.read(rnd);
}
示例8: handleGradeItem
import org.azeckoski.reflectutils.transcoders.JSONTranscoder; //导入依赖的package包/类
@EntityCustomAction(action = "gradeitem", viewKey = "")
public GradebookItem handleGradeItem(EntityView view) {
String courseId = view.getPathSegment(2);
if (courseId == null) {
throw new IllegalArgumentException(
"valid courseId must be included in the URL /grades/gradeitem/{courseId}");
}
String userId = externalLogic.getCurrentUserId();
if (userId == null) {
throw new SecurityException(
"Only logged in users can access instructor courses listings");
}
if (!externalLogic.isUserAdmin(userId) && !externalLogic.isUserInstructor(userId)) {
throw new SecurityException("Only instructors can access course gradebook");
}
GradebookItem gbItemOut;
if (Method.GET.toString().equalsIgnoreCase(view.getMethod())) {
String gradeItemName = view.getPathSegment(3);
if (gradeItemName == null) {
throw new IllegalArgumentException(
"valid gbItemName must be included in the URL /grades/gradeitem/{courseId}/{gradeItemName}");
}
Gradebook gb = externalLogic.getCourseGradebook(courseId, gradeItemName);
gbItemOut = gb.items.get(0);
} else if (Method.POST.toString().equalsIgnoreCase(view.getMethod())
|| Method.PUT.toString().equalsIgnoreCase(view.getMethod())) {
ServletRequest request = requestGetter.getRequest();
if (request == null) {
throw new IllegalStateException("Cannot get request to read data from");
}
String inputData;
try {
inputData = readerToString(request.getReader());
} catch (IOException e) {
throw new RuntimeException("Failed to read the data from the request: " + e);
}
if (inputData == null || "".equals(inputData)) {
throw new IllegalStateException("Must include the grade item and grades data for input (sent nothing)");
}
Map<String, Object> input;
if (Formats.JSON.equals(view.getFormat())) {
input = new JSONTranscoder().decode(inputData);
} else {
input = new XMLTranscoder().decode(inputData);
}
// loop through and get the data out and put it into a gradeitem
ConversionUtils cvu = ConversionUtils.getInstance();
String gbItemName = (String) input.get("name");
GradebookItem gbItemIn = new GradebookItem(courseId, gbItemName);
gbItemIn.pointsPossible = cvu.convert(input.get("pointsPossible"), Double.class);
gbItemIn.dueDate = cvu.convert(input.get("dueDate"), Date.class);
gbItemIn.eid = cvu.convert(input.get("externalID"), String.class);
@SuppressWarnings("unchecked")
List<Object> scores = cvu.convert(input.get("scores"), List.class);
if (scores != null) {
for (Object o : scores) {
GradebookItemScore score = cvu.convert(o, GradebookItemScore.class);
gbItemIn.scores.add( score );
}
}
gbItemOut = externalLogic.saveGradebookItem(gbItemIn);
} else {
throw new EntityException("Method ("+view.getMethod()+") not supported", "grades/gradeitem", HttpServletResponse.SC_METHOD_NOT_ALLOWED);
}
return gbItemOut;
}