import javax.xml.bind.DatatypeConverter; public static String toHexString(byte[] array) { return DatatypeConverter.printHexBinary(array); } public static byte[] toByteArray(String s) { return DatatypeConverter.parseHexBinary(s); }
javax.xml.bind.DatatypeConverter.parseDateTime("2010-01-01T12:00:00Z")
private JAXBContext contextForType(Class<?> type) { try { return context != null ? context : JAXBContext.newInstance(type); } catch (JAXBException e) { throw new IllegalArgumentException(e); } } }
@Override public T convert(ResponseBody value) throws IOException { try { Unmarshaller unmarshaller = context.createUnmarshaller(); XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(value.charStream()); return unmarshaller.unmarshal(streamReader, type).getValue(); } catch (JAXBException | XMLStreamException e) { throw new RuntimeException(e); } finally { value.close(); } } }
public JAXBElement<Long> primitiveLong() { return new JAXBElement<>(NAME, Long.class, 42L); }
public Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException { JAXBContext jaxbContext = getJaxbContext(clazz); return jaxbContext.createUnmarshaller(); }
public Marshaller createMarshaller(Class<?> clazz) throws JAXBException { JAXBContext jaxbContext = getJaxbContext(clazz); return jaxbContext.createMarshaller(); }
@Override protected void customizeUnmarshaller(Unmarshaller unmarshaller) { unmarshaller.setAdapter(new MyCustomElementAdapter()); } }
@Override protected void customizeMarshaller(Marshaller marshaller) { marshaller.setAdapter(new MyCustomElementAdapter()); }
public JAXBElement<QName> standardClassQName() { return new JAXBElement<>(NAME, QName.class, NAME); }
/** * Return a newly created JAXB marshaller. JAXB marshallers are not necessarily thread safe. */ protected Marshaller createMarshaller() { try { Marshaller marshaller = getJaxbContext().createMarshaller(); initJaxbMarshaller(marshaller); return marshaller; } catch (JAXBException ex) { throw convertJaxbException(ex); } }
public JAXBElement<Byte> primitiveByte() { return new JAXBElement<>(NAME, Byte.class, (byte) 42); }
public JAXBElement<byte[]> primitiveByteArray() { return new JAXBElement<>(NAME, byte[].class, new byte[] {42}); }
public JAXBElement<String> standardClassString() { return new JAXBElement<>(NAME, String.class, "42"); }
public JAXBElement<Boolean> primitiveBoolean() { return new JAXBElement<>(NAME, Boolean.class, true); }
public JAXBElement<Short> primitiveShort() { return new JAXBElement<>(NAME, Short.class, (short) 42); }
public JAXBElement<Integer> primitiveInteger() { return new JAXBElement<>(NAME, Integer.class, 42); }
public JAXBElement<Double> primitiveDouble() { return new JAXBElement<>(NAME, Double.class, 42D); }
public JAXBElement<Duration> standardClassDuration() { Duration duration = factory.newDuration(42000); return new JAXBElement<>(NAME, Duration.class, duration); }
public JAXBElement<BigDecimal> standardClassBigDecimal() { return new JAXBElement<>(NAME, BigDecimal.class, new BigDecimal("42.0")); }