Here you can find the source of convertToString(Object obj)
Parameter | Description |
---|---|
args | a parameter |
public static String convertToString(Object obj)
//package com.java2s; /**//from www. j a v a 2 s . c o m * ============================================================================= * * ORCID (R) Open Source * http://orcid.org * * Copyright (c) 2012-2014 ORCID, Inc. * Licensed under an MIT-Style License (MIT) * http://orcid.org/open-source-license * * This copyright and license information (including a link to the full license) * shall be included in its entirety in all copies or substantial portion of * the software. * * ============================================================================= */ import java.io.StringWriter; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { /** * @param args */ public static String convertToString(Object obj) { try { JAXBContext context = JAXBContext.newInstance(obj.getClass()); StringWriter writer = new StringWriter(); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(obj, writer); return writer.toString(); } catch (JAXBException e) { return ("Unable to unmarshal because: " + e); } } }