コード例 #1
0
ファイル: JerseyClient.java プロジェクト: BCDH/TEI-Completer
  private Suggestions transformJsonResponse(final InputStream is, final Path transformation)
      throws IOException, TransformationException {
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
      jsonTransformer.transform(is, transformation, os);

      try (final InputStream resultIs = new ByteArrayInputStream(os.toByteArray())) {
        final JAXBContext context =
            org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(
                new Class[] {Suggestions.class}, null);

        final Unmarshaller unmarshaller = context.createUnmarshaller();
        unmarshaller.setProperty(
            UnmarshallerProperties.MEDIA_TYPE,
            org.eclipse.persistence.oxm.MediaType.APPLICATION_JSON);
        unmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX, null);
        unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, false);
        unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
        unmarshaller.setProperty(
            UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper);
        unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR, ':');

        final JAXBElement<Suggestions> jaxbElement =
            unmarshaller.unmarshal(new StreamSource(resultIs), Suggestions.class);
        return jaxbElement.getValue();
      } catch (final JAXBException e) {
        throw new TransformationException(e);
      }
    }
  }
コード例 #2
0
ファイル: JerseyClient.java プロジェクト: BCDH/TEI-Completer
  private Suggestions transformXmlResponse(final InputStream is, final Path transformation)
      throws IOException, TransformationException {
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
      xmlTransformer.transform(is, transformation, os);

      try (final InputStream resultIs = new ByteArrayInputStream(os.toByteArray())) {
        final JAXBContext context = JAXBContext.newInstance(Suggestions.class);
        final Unmarshaller unmarshaller = context.createUnmarshaller();
        return (Suggestions) unmarshaller.unmarshal(resultIs);
      } catch (final JAXBException e) {
        throw new TransformationException(e);
      }
    }
  }