Here you can find the source of fromStream(Class jaxbClass, InputStream is)
Parameter | Description |
---|---|
jaxbClass | a parameter |
is | stream to read to construct the object |
Parameter | Description |
---|---|
Exception | an exception |
public static Object fromStream(Class jaxbClass, InputStream is) throws Exception
//package com.java2s; /**//from w w w. java2s . c om * This document is a part of the source code and related artifacts * for CollectionSpace, an open source collections management system * for museums and related institutions. * http://www.collectionspace.org * http://wiki.collectionspace.org * Copyright 2010 University of California at Berkeley * Licensed under the Educational Community License (ECL), Version 2.0. * You may not use this file except in compliance with this License. * You may obtain a copy of the ECL 2.0 License at * https://source.collectionspace.org/collection-space/LICENSE.txt * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.InputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; public class Main { /** * fromStream retrieves object of given class from given inputstream * @param jaxbClass * @param is stream to read to construct the object * @return * @throws Exception */ public static Object fromStream(Class jaxbClass, InputStream is) throws Exception { JAXBContext context = JAXBContext.newInstance(jaxbClass); Unmarshaller unmarshaller = context.createUnmarshaller(); //note: setting schema to null will turn validator off unmarshaller.setSchema(null); return jaxbClass.cast(unmarshaller.unmarshal(is)); } }