本文整理汇总了Java中com.fasterxml.jackson.annotation.JsonRootName类的典型用法代码示例。如果您正苦于以下问题:Java JsonRootName类的具体用法?Java JsonRootName怎么用?Java JsonRootName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonRootName类属于com.fasterxml.jackson.annotation包,在下文中一共展示了JsonRootName类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAll
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
@Authentication({User.Role.ADMIN, User.Role.READONLY_ADMIN})
public static Result getAll() {
ExpressionList<Basestation> exp = QueryHelper.buildQuery(Basestation.class, Basestation.FIND.where());
List<JsonHelper.Tuple> tuples = exp.findList().stream().map(basestation -> new JsonHelper.Tuple(basestation, new ControllerHelper.Link("self",
controllers.routes.BasestationController.get(basestation.getId()).absoluteURL(request())))).collect(Collectors.toList());
// TODO: add links when available
List<ControllerHelper.Link> links = new ArrayList<>();
links.add(new ControllerHelper.Link("self", controllers.routes.BasestationController.getAll().absoluteURL(request())));
links.add(new ControllerHelper.Link("total", controllers.routes.BasestationController.getTotal().absoluteURL(request())));
try {
JsonNode result = JsonHelper.createJsonNode(tuples, links, Basestation.class);
String[] totalQuery = request().queryString().get("total");
if (totalQuery != null && totalQuery.length == 1 && totalQuery[0].equals("true")) {
ExpressionList<Basestation> countExpression = QueryHelper.buildQuery(Basestation.class, Basestation.FIND.where(), true);
String root = Basestation.class.getAnnotation(JsonRootName.class).value();
((ObjectNode) result.get(root)).put("total",countExpression.findRowCount());
}
return ok(result);
} catch(JsonProcessingException ex) {
play.Logger.error(ex.getMessage(), ex);
return internalServerError();
}
}
示例2: getAll
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
@Authentication({User.Role.READONLY_ADMIN, User.Role.ADMIN})
public static Result getAll() {
ExpressionList<Assignment> exp = QueryHelper.buildQuery(Assignment.class, Assignment.FIND.where());
List<JsonHelper.Tuple> tuples = exp.findList().stream().map(assignment -> new JsonHelper.Tuple(assignment, new ControllerHelper.Link("self",
controllers.routes.AssignmentController.get(assignment.getId()).absoluteURL(request())))).collect(Collectors.toList());
// TODO: add links when available
List<ControllerHelper.Link> links = new ArrayList<>();
links.add(new ControllerHelper.Link("self", controllers.routes.AssignmentController.getAll().absoluteURL(request())));
links.add(new ControllerHelper.Link("total", controllers.routes.AssignmentController.getTotal().absoluteURL(request())));
try {
JsonNode result = JsonHelper.createJsonNode(tuples, links, Assignment.class);
String[] totalQuery = request().queryString().get("total");
if (totalQuery != null && totalQuery.length == 1 && totalQuery[0].equals("true")) {
ExpressionList<Assignment> countExpression = QueryHelper.buildQuery(Assignment.class, Assignment.FIND.where(), true);
String root = Assignment.class.getAnnotation(JsonRootName.class).value();
((ObjectNode) result.get(root)).put("total",countExpression.findRowCount());
}
return ok(result);
} catch(JsonProcessingException ex) {
play.Logger.error(ex.getMessage(), ex);
return internalServerError();
}
}
示例3: parseResponse
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
/**
* Parse response into data model object.
*
* @param unwrap Unwrap datamodel
* @return Response datamodel
* @throws IOException
*/
public T parseResponse() throws IOException {
ObjectReader reader = MAPPER.readerFor(datamodel).without(Feature.AUTO_CLOSE_SOURCE);
if (datamodel.isAnnotationPresent(JsonRootName.class)) {
reader = reader.with(DeserializationFeature.UNWRAP_ROOT_VALUE);
}
try (final InputStream is = response.getStream()) {
final T result = reader.readValue(is);
/*
* ObjectReader.readValue might not consume the entire inputstream,
* we skip everything after the json root element.
* This is needed for proper http connection reuse (keep alive).
*/
is.skip(Long.MAX_VALUE);
return result;
}
}
示例4: buildConstructor
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
/**
* Build the constructor.
*
* @param mappedTypeClass the type to map
*
* @return the constructor method
*/
private MethodSpec buildConstructor( JClassType mappedTypeClass ) {
Optional<JsonRootName> jsonRootName
= findFirstEncounteredAnnotationsOnAllHierarchy( configuration, mappedTypeClass, JsonRootName.class );
String rootName;
if ( !jsonRootName.isPresent() || Strings.isNullOrEmpty( jsonRootName.get().value() ) ) {
rootName = mappedTypeClass.getSimpleSourceName();
} else {
rootName = jsonRootName.get().value();
}
return MethodSpec.constructorBuilder()
.addModifiers( Modifier.PUBLIC )
.addStatement( "super($S)", rootName )
.build();
}
示例5: getAll
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
@Authentication({User.Role.ADMIN, User.Role.READONLY_ADMIN})
public static Result getAll() {
ExpressionList<User> exp = QueryHelper.buildQuery(User.class, User.FIND.where());
List<JsonHelper.Tuple> tuples = exp.findList().stream().map(user -> new JsonHelper.Tuple(user, new ControllerHelper.Link("self",
controllers.routes.UserController.get(user.getId()).absoluteURL(request())))).collect(Collectors.toList());
// TODO: add links when available
List<ControllerHelper.Link> links = new ArrayList<>();
links.add(new ControllerHelper.Link("self", controllers.routes.UserController.getAll().absoluteURL(request())));
links.add(new ControllerHelper.Link("total", controllers.routes.UserController.getTotal().absoluteURL(request())));
links.add(new ControllerHelper.Link("me", controllers.routes.UserController.currentUser().absoluteURL(request())));
try {
JsonNode result = JsonHelper.createJsonNode(tuples, links, User.class);
String[] totalQuery = request().queryString().get("total");
if (totalQuery != null && totalQuery.length == 1 && totalQuery[0].equals("true")) {
ExpressionList<User> countExpression = QueryHelper.buildQuery(User.class, User.FIND.where(), true);
String root = User.class.getAnnotation(JsonRootName.class).value();
((ObjectNode) result.get(root)).put("total",countExpression.findRowCount());
}
return ok(result);
} catch(JsonProcessingException ex) {
play.Logger.error(ex.getMessage(), ex);
return internalServerError();
}
}
示例6: getAll
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
@Authentication({User.Role.ADMIN, User.Role.READONLY_ADMIN})
public static Result getAll() {
ExpressionList<Drone> exp = QueryHelper.buildQuery(Drone.class, Drone.FIND.where(),false);
List<JsonHelper.Tuple> tuples = exp.findList().stream().map(drone -> new JsonHelper.Tuple(drone, new ControllerHelper.Link("self",
controllers.routes.DroneController.get(drone.getId()).absoluteURL(request())))).collect(Collectors.toList());
// TODO: add links when available
List<ControllerHelper.Link> links = new ArrayList<>();
links.add(new ControllerHelper.Link("self", controllers.routes.DroneController.getAll().absoluteURL(request())));
links.add(new ControllerHelper.Link("total", controllers.routes.DroneController.getTotal().absoluteURL(request())));
links.add(new ControllerHelper.Link("types", controllers.routes.DroneController.getSuportedTypes().absoluteURL(request())));
try {
JsonNode result = JsonHelper.createJsonNode(tuples, links, Drone.class);
String[] totalQuery = request().queryString().get("total");
if (totalQuery != null && totalQuery.length == 1 && totalQuery[0].equals("true")) {
ExpressionList<Drone> countExpression = QueryHelper.buildQuery(Drone.class, Drone.FIND.where(), true);
String root = Drone.class.getAnnotation(JsonRootName.class).value();
((ObjectNode) result.get(root)).put("total",countExpression.findRowCount());
}
return ok(result);
} catch(JsonProcessingException ex) {
play.Logger.error(ex.getMessage(), ex);
return internalServerError();
}
}
示例7: removeRootElement
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
public static JsonNode removeRootElement(JsonNode node, Class clazz, boolean isList) throws InvalidJSONException {
JsonRootName annotation = (JsonRootName) clazz.getAnnotation(JsonRootName.class);
String rootElement = annotation.value();
JsonNode rootNode = isList ? node.get(rootElement).get(DEFAULT_ROOT_ELEMENT) : node.get(rootElement);
if(rootNode == null)
throw new InvalidJSONException("Invalid json: no such element (" +
(isList ? DEFAULT_ROOT_ELEMENT : annotation.value()) + ")");
return rootNode;
}
示例8: addRootElement
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
public static JsonNode addRootElement(JsonNode node, Class clazz) {
JsonRootName annotation = (JsonRootName) clazz.getAnnotation(JsonRootName.class);
String rootElement = annotation.value();
ObjectNode nodeWithRoot = Json.newObject();
nodeWithRoot.put(rootElement, node);
return nodeWithRoot;
}
示例9: getItemResourceRelFor
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
@Override
public String getItemResourceRelFor(Class<?> type)
{
Class<?> baseType = determineBaseType(type);
JsonRootName rootName = getAnnotationByType(baseType, JsonRootName.class);
return (rootName == null) ? defaultRelProvider.getItemResourceRelFor(baseType) : rootName.value();
}
示例10: findRootName
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
public PropertyName findRootName(AnnotatedClass paramAnnotatedClass)
{
JsonRootName localJsonRootName = (JsonRootName)paramAnnotatedClass.getAnnotation(JsonRootName.class);
if (localJsonRootName == null)
return null;
return new PropertyName(localJsonRootName.value());
}
示例11: fromJsonRoot
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
private Optional<String> fromJsonRoot(Class<?> type) {
return stream(type.getAnnotationsByType(JsonRootName.class))
.findFirst()
.map(JsonRootName::value);
}
示例12: rootNameFor
import com.fasterxml.jackson.annotation.JsonRootName; //导入依赖的package包/类
private static String rootNameFor(Class<?> type) {
JsonRootName rootName = type.getAnnotation(JsonRootName.class);
return rootName == null ? type.getSimpleName() : rootName.value();
}