当前位置: 首页>>代码示例>>Java>>正文


Java ObjectMapper.readValue方法代码示例

本文整理汇总了Java中org.boon.json.ObjectMapper.readValue方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.readValue方法的具体用法?Java ObjectMapper.readValue怎么用?Java ObjectMapper.readValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.boon.json.ObjectMapper的用法示例。


在下文中一共展示了ObjectMapper.readValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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


注:本文中的org.boon.json.ObjectMapper.readValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。