本文整理汇总了Java中org.boon.json.ObjectMapper类的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper类的具体用法?Java ObjectMapper怎么用?Java ObjectMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectMapper类属于org.boon.json包,在下文中一共展示了ObjectMapper类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testBadInstance
import org.boon.json.ObjectMapper; //导入依赖的package包/类
@Test
public void testBadInstance() throws Exception
{
Cluster cluster = ((ProtocolImpl)((CBConnection) con).protocol).getCluster();
String endpoint = "{\"cluster\":\"default\",\"name\":\"10.168.209.119\",\"queryEndpoint\":\"http://10.168.209.119:8093/query/service\"," +
"\"adminEndpoint\":\"http://10.168.209.119:8093/admin\",\"options\":null}";
ObjectMapper mapper = JsonFactory.create();
Map <String,Object> instanceEndpoint = (Map)mapper.fromJson(endpoint);
cluster.addEndPoint(instanceEndpoint);
assertNotNull(con);
Statement statement = con.createStatement();
assertNotNull(statement);
// there are only 4 endpoints we added 1 which is 5
for (int i = 0; i++< 6;)
{
int inserted = statement.executeUpdate("INSERT INTO default (KEY, VALUE) VALUES ( 'K" + i +"'," + i +")");
assertEquals(1, inserted);
}
}
开发者ID:jdbc-json,项目名称:jdbc-cb,代码行数:27,代码来源:ClusterTest.java
示例2: toJsonString
import org.boon.json.ObjectMapper; //导入依赖的package包/类
public static <T> String toJsonString(T document) {
JsonSerializerFactory serializer = new JsonSerializerFactory().addFilter(new FieldFilter() {
@Override
public boolean include(Object o, FieldAccess fieldAccess) {
if ( fieldAccess.hasAnnotation(DocumentRef.class.getName())) {
return false;
}
return true;
}
});
ObjectMapper mapper = JsonFactory.create(null, serializer);
return mapper.toJson(document);
}
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:19,代码来源:PgsqlJsonRepository.java
示例3: send
import org.boon.json.ObjectMapper; //导入依赖的package包/类
public void send(Object obj) {
if (httpServerExchange.getRequestMethod()
.equals(HEAD)) {
httpServerExchange.endExchange();
return;
}
httpServerExchange.getResponseHeaders()
.put(Headers.CONTENT_TYPE, JSON_CONTENT_TYPE);
ObjectMapper objectMapper = LOCAL_MAPPER.get();
if (objectMapper == null) {
LOGGER.info("Creating new parser.........");
objectMapper = JsonFactory.createUseJSONDates();
LOCAL_MAPPER.set(objectMapper);
}
String jsonStr = objectMapper
.toJson(obj);
ByteBuffer byteBuffer = ByteBuffer.wrap(jsonStr.getBytes(StandardCharsets.UTF_8));
StreamSinkChannel responseChannel = httpServerExchange.getResponseChannel();
int written;
try {
do {
written = responseChannel.write(byteBuffer);
} while (byteBuffer.hasRemaining() && written > 0);
} catch (IOException e) {
LOGGER.error("Can not write response: " + e.getMessage(), e);
}
}
开发者ID:icha024,项目名称:spur,代码行数:30,代码来源:Res.java
示例4: setSqlJson
import org.boon.json.ObjectMapper; //导入依赖的package包/类
@Test
public void setSqlJson() throws Exception
{
String json = "{\n" +
" \"emailAddress\": \"[email protected]\",\n" +
" \"type\": \"customer\",\n" +
" \"dateLastActive\": \"2014-05-06T15:52:14Z\",\n" +
" \"firstName\": \"Darrin\",\n" +
" \"phoneNumber\": \"497-854-2229 x000\",\n" +
" \"postalCode\": \"45603-9112\",\n" +
" \"lastName\": \"Ortiz\",\n" +
" \"ccInfo\": {\n" +
" \"cardNumber\": \"1234-2121-1221-1211\",\n" +
" \"cardType\": \"discover\",\n" +
" \"cardExpiry\": \"2012-11-12\"\n" +
" },\n" +
" \"dateAdded\": \"2013-06-10T15:52:14Z\",\n" +
" \"state\": \"IN\",\n" +
" \"customerId\": \"customer10\"\n" +
"}";
ObjectMapper mapper = JsonFactory.create();
Map <String,Object> jsonObject = mapper.readValue(json, Map.class);
String query = "insert into default (key,value) values (?,?)";
SQLJSON sqljson = ((CBConnection)con).createSQLJSON();
sqljson.setMap( jsonObject );
try (PreparedStatement pstmt = con.prepareStatement(query))
{
pstmt.setString(1,"customer1");
((CBPreparedStatement)pstmt).setSQLJSON(2,sqljson);
assertEquals(1,pstmt.executeUpdate());
}
}
开发者ID:jdbc-json,项目名称:jdbc-cb,代码行数:36,代码来源:TestSQLJson.java
示例5: save
import org.boon.json.ObjectMapper; //导入依赖的package包/类
@Test
public void save() throws Exception {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
EventRepositoryFS repo = new EventRepositoryFS("test.json");
Beer b1 = new Beer("Åbro Orginal", "Damm", "Lager", 213124, 23.2, "Åbro", "Sverige", "", 5.2, "flaska", "öl", true, 50, formatter.parse("2005-10-01"), "Åbro", "", 213124);
Beer b2 = new Beer("Norrlands guld", "Hopps", "Lager", 14127, 19.5, "Spendrups", "Sverige", "", 5, "flaska", "öl", true, 330, formatter.parse("2005-10-01"), "Spendrups", "", 14127);
Beer b3 = new Beer("Åbro Orginal", "Damm", "Lager", 213124, 23.2, "Åbro", "England", "", 5.2, "flaska", "öl", true, 50, formatter.parse("2005-10-01"), "Åbro", "", 213124);
Beer b4 = new Beer("Falcon", "Njet", "Lager", 95483, 20, "Falcon", "Sverige", "", 4.8, "flaska", "öl", true, 335, formatter.parse("1999-10-01"), "Spendrups", "", 95483);
Event e1 = new Event(213124, Event.Action.Update, b1, b3);
Event e2 = new Event(14127, Event.Action.Create, new Beer(), b2);
Event e3 = new Event(95483, Event.Action.Delete, b4, new Beer());
List<Event> eventList = new ArrayList<>();
eventList.add(e1);
eventList.add(e2);
eventList.add(e3);
repo.save(eventList);
ObjectMapper mapper = JsonFactory.create();
List<Event> events = new ArrayList<>();
try {
events = mapper.readValue(new FileInputStream("test.json"), List.class, Event.class);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//puts("events", events);
System.out.println(eventList.get(0).toString());
System.out.println(events.get(0).toString());
assertEquals(eventList, events);
}
开发者ID:oskarp,项目名称:beercrawler,代码行数:39,代码来源:EventRepositoryFSTest.java
示例6: convertBodyStringToObj
import org.boon.json.ObjectMapper; //导入依赖的package包/类
private void convertBodyStringToObj(PostParseConsumer objectConsumer, HttpServerExchange exchange, String str) {
if (bodyClassType.equals(String.class)) {
this.body = (T) str;
objectConsumer.postParse(exchange, str);
return;
}
ObjectMapper objectMapper = LOCAL_MAPPER.get();
if (objectMapper == null) {
objectMapper = JsonFactory.createUseJSONDates();
LOCAL_MAPPER.set(objectMapper);
}
T parsedType;
try {
parsedType = objectMapper.readValue(str, bodyClassType);
} catch (Exception e) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
if (parsedType == null) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.endExchange();
return;
}
Set<ConstraintViolation<T>> constraintViolations = validator.validate(parsedType);
if (constraintViolations.isEmpty()) {
this.body = parsedType;
objectConsumer.postParse(exchange, parsedType);
} else {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
exchange.getResponseSender()
.send(objectMapper.toJson(new InvalidValues(constraintViolations.stream()
.map(violation -> violation.getPropertyPath()
.toString())
.collect(Collectors.toList()))));
exchange.endExchange();
}
}
开发者ID:icha024,项目名称:spur,代码行数:43,代码来源:Req.java
示例7: handleClusterResponse
import org.boon.json.ObjectMapper; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public Cluster handleClusterResponse(CloseableHttpResponse response) throws IOException
{
int status = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
String string = EntityUtils.toString(entity);
logger.trace ("Cluster response {}", string);
ObjectMapper mapper = JsonFactory.create();
// has to be an object here since we can get a 404 back which is a string
Object jsonArray = mapper.fromJson(string);
String message="";
switch (status)
{
case 200:
//noinspection unchecked
rewriteURLs((List<Map>)jsonArray);
return new Cluster((List)jsonArray, ssl);
case 400:
message = "Bad Request";
break;
case 401:
message = "Unauthorized Request credentials are missing or invalid";
break;
case 403:
message = "Forbidden Request: read only violation or client unauthorized to modify";
break;
case 404:
message = "Not found: Check the URL";
break;
case 405:
message = "Method not allowed: The REST method type in request is supported";
break;
case 409:
message = "Conflict: attempt to create a keyspace or index that already exists";
break;
case 410:
message = "Gone: The server is doing a graceful shutdown";
break;
case 500:
message = "Internal server error: unforeseen problem processing the request";
break;
case 503:
message = "Service Unavailable: there is an issue preventing the request from being serv serviced";
break;
}
throw new ClientProtocolException(message +": " + status);
}
开发者ID:jdbc-json,项目名称:jdbc-cb,代码行数:52,代码来源:ProtocolImpl.java
示例8: getObjectMapper
import org.boon.json.ObjectMapper; //导入依赖的package包/类
public ObjectMapper getObjectMapper() {
return this.objectMapper;
}
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:BoonDataFormat.java
示例9: createInstanceFromJsonString
import org.boon.json.ObjectMapper; //导入依赖的package包/类
public static <T> T createInstanceFromJsonString(final Class<T> document,final String jsonData) {
ObjectMapper mapper = JsonFactory.create();
return mapper.readValue(jsonData,document);
}
开发者ID:wmira,项目名称:nosql-jdbc,代码行数:5,代码来源:PgsqlJsonRepository.java
示例10: BoonDataFormat
import org.boon.json.ObjectMapper; //导入依赖的package包/类
/**
* Use a custom unmarshal type and Boon mapper
*
* @param mapper the custom mapper
* @param unmarshalType the custom unmarshal type
*/
public BoonDataFormat(Class<?> unmarshalType, ObjectMapper mapper) {
this.unmarshalType = unmarshalType;
this.objectMapper = mapper;
}
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:BoonDataFormat.java
注:本文中的org.boon.json.ObjectMapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论