List of usage examples for com.fasterxml.jackson.databind.type TypeFactory defaultInstance
public static TypeFactory defaultInstance()
From source file:com.linecorp.platform.channel.sample.Main.java
public static void main(String[] args) { BusinessConnect bc = new BusinessConnect(); /**//from w w w.ja va 2s . com * Prepare the required channel secret and access token */ String channelSecret = System.getenv("CHANNEL_SECRET"); String channelAccessToken = System.getenv("CHANNEL_ACCESS_TOKEN"); if (channelSecret == null || channelSecret.isEmpty() || channelAccessToken == null || channelAccessToken.isEmpty()) { System.err.println("Error! Environment variable CHANNEL_SECRET and CHANNEL_ACCESS_TOKEN not defined."); return; } port(Integer.valueOf(System.getenv("PORT"))); staticFileLocation("/public"); /** * Define the callback url path */ post("/events", (request, response) -> { String requestBody = request.body(); /** * Verify whether the channel signature is valid or not */ String channelSignature = request.headers("X-LINE-CHANNELSIGNATURE"); if (channelSignature == null || channelSignature.isEmpty()) { response.status(400); return "Please provide valid channel signature and try again."; } if (!bc.validateBCRequest(requestBody, channelSecret, channelSignature)) { response.status(401); return "Invalid channel signature."; } /** * Parse the http request body */ ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); objectMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance())); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); EventList events; try { events = objectMapper.readValue(requestBody, EventList.class); } catch (IOException e) { response.status(400); return "Invalid request body."; } ApiHttpClient apiHttpClient = new ApiHttpClient(channelAccessToken); /** * Process the incoming messages/operations one by one */ List<String> toUsers; for (Event event : events.getResult()) { switch (event.getEventType()) { case Constants.EventType.MESSAGE: toUsers = new ArrayList<>(); toUsers.add(event.getContent().getFrom()); // @TODO: We strongly suggest you should modify this to process the incoming message/operation async bc.sendTextMessage(toUsers, "You said: " + event.getContent().getText(), apiHttpClient); break; case Constants.EventType.OPERATION: if (event.getContent().getOpType() == Constants.OperationType.ADDED_AS_FRIEND) { String newFriend = event.getContent().getParams().get(0); Profile profile = bc.getProfile(newFriend, apiHttpClient); String displayName = profile == null ? "Unknown" : profile.getDisplayName(); toUsers = new ArrayList<>(); toUsers.add(newFriend); bc.sendTextMessage(toUsers, displayName + ", welcome to be my friend!", apiHttpClient); Connection connection = null; connection = DatabaseUrl.extract().getConnection(); toUsers = bc.getFriends(newFriend, connection); if (toUsers.size() > 0) { bc.sendTextMessage(toUsers, displayName + " just join us, let's welcome him/her!", apiHttpClient); } bc.addFriend(newFriend, displayName, connection); if (connection != null) { connection.close(); } } break; default: // Unknown type? } } return "Events received successfully."; }); get("/", (request, response) -> { Map<String, Object> attributes = new HashMap<>(); attributes.put("message", "Hello World!"); return new ModelAndView(attributes, "index.ftl"); }, new FreeMarkerEngine()); }
From source file:net.turnbig.jdbcx.utilities.JsonMapper.java
@SuppressWarnings("deprecation") public static void main(String[] args) { String json = "[{\"asddd\":1}"; boolean isJson = true; try {/*w w w. ja v a2s . c om*/ ObjectMapper m = new ObjectMapper(); if (json.trim().startsWith("[")) { JavaType typeRef = TypeFactory.defaultInstance().constructParametricType(List.class, Map.class); m.readValue(json, typeRef); } else { JavaType typeRef = TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class); m.readValue(json, typeRef); m.readValue(json, typeRef); } } catch (Exception e) { isJson = false; } System.out.println(isJson); }
From source file:com.github.jasonruckman.sidney.core.type.Types.java
public static TypeBindings binding(Type clazz) { JavaType javaType = TypeFactory.defaultInstance().constructType(clazz); return new TypeBindings(TypeFactory.defaultInstance(), javaType); }
From source file:org.baswell.routes.JacksonBridge.java
static <RequestContentType extends Object> RequestContentType parseJackson(byte[] contentBytes, Type contentType) throws IOException { return (RequestContentType) new ObjectMapper().readValue(contentBytes, TypeFactory.defaultInstance().constructType(contentType)); }
From source file:com.github.jasonruckman.sidney.core.type.Types.java
public static JavaType type(TypeRef typeRef) { JavaType[] params = new JavaType[typeRef.getTypeParameters().size()]; for (int i = 0; i < params.length; i++) { params[i] = type(typeRef.getTypeParameters().get(i)); }//from w w w. j a v a2s .c o m return TypeFactory.defaultInstance().constructParametricType(typeRef.getType(), params); }
From source file:com.github.jasonruckman.sidney.core.type.Types.java
public static TypeBindings binding(TypeRef typeRef) { return new TypeBindings(TypeFactory.defaultInstance(), type(typeRef)); }
From source file:com.thoughtworks.studios.journey.utils.JSONUtils.java
public static List<Map> jsonToListMap(String json) throws IOException { return MAPPER.readValue(json, TypeFactory.defaultInstance().constructCollectionType(List.class, Map.class)); }
From source file:com.github.jasonruckman.sidney.core.type.Types.java
public static TypeBindings binding(Type clazz, TypeBindings parentBindings) { JavaType javaType = TypeFactory.defaultInstance().constructType(clazz, parentBindings); return new TypeBindings(TypeFactory.defaultInstance(), javaType); }
From source file:com.uimirror.core.framework.rest.util.ObjectMapperFactory.java
private static AnnotationIntrospector getAnnotationPair() { final AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); return AnnotationIntrospector.pair(primary, secondary); }
From source file:info.archinnov.achilles.json.DefaultJacksonMapper.java
private static ObjectMapper defaultJacksonMapper() { ObjectMapper defaultMapper = new ObjectMapper(); defaultMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); defaultMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); defaultMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); defaultMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary)); return defaultMapper; }