本文整理匯總了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();
}