2 * Copyright (C) 2015 IBM, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.neutron.spi;
11 import java.io.StringReader;
13 import javax.xml.bind.JAXBException;
15 import com.sun.jersey.api.json.JSONConfiguration;
16 import com.sun.jersey.api.json.JSONJAXBContext;
17 import com.sun.jersey.api.json.JSONUnmarshaller;
19 public class JaxbTestHelper {
21 @SuppressWarnings({ "rawtypes", "unchecked" })
22 public static Object jaxbUnmarshall(Object schemaObject, String json) throws JAXBException {
23 Class c = schemaObject.getClass();
24 Class[] types = new Class[1];
26 JSONJAXBContext context = new JSONJAXBContext(JSONConfiguration.natural().build(), types);
27 JSONUnmarshaller unmarshaller = context.createJSONUnmarshaller();
28 StringReader reader = new StringReader(json);
29 return unmarshaller.unmarshalFromJSON(reader, c);