@Test public void testTextToObjectConversion() { String source = "Can the maker repair what he makes?"; String source2 = "I had your job once. I was good at it."; byte[] sourceBytes = source2.getBytes(US_ASCII); Object result = StandardConversions.convertTextToObject(source, APPLICATION_OBJECT); Object result2 = StandardConversions.convertTextToObject(sourceBytes, TEXT_PLAIN.withCharset(US_ASCII)); assertEquals(source, result); assertEquals(source2, result2); }
public static String convertTextToObject(Object source, MediaType sourceType) { if (source == null) return null; if (source instanceof String) return source.toString(); if (source instanceof byte[]) { byte[] bytesSource = (byte[]) source; return new String(bytesSource, sourceType.getCharset()); } throw CONTAINER.invalidTextContent(source); }
StandardConversions { public static String convertTextToObject(Object source, MediaType sourceType) { if (source == null) return null; if (source instanceof String) return source.toString(); if (source instanceof byte[]) { byte[] bytesSource = (byte[]) source; return new String(bytesSource, sourceType.getCharset()); } throw CONTAINER.invalidTextContent(source); } }
StandardConversions { public static String convertTextToObject(Object source, MediaType sourceType) { if (source == null) return null; if (source instanceof String) return source.toString(); if (source instanceof byte[]) { byte[] bytesSource = (byte[]) source; return new String(bytesSource, sourceType.getCharset()); } throw CONTAINER.invalidTextContent(source); }  }
StandardConversions { public static String convertTextToObject(Object source, MediaType sourceType) { if (source == null) return null; if (source instanceof String) return source.toString(); if (source instanceof byte[]) { byte[] bytesSource = (byte[]) source; return new String(bytesSource, sourceType.getCharset()); } throw CONTAINER.invalidTextContent(source); }  static Object convertTextToText(Object source, MediaType sourceType, MediaType destinationType); static byte[] convertTextToOctetStream(Object source, MediaType sourceType); static String convertTextToObject(Object source, MediaType sourceType); static String convertTextToUrlEncoded(Object source, MediaType sourceType); static byte[] convertOctetStreamToText(byte[] source, MediaType destination); static Object convertOctetStreamToJava(byte[] source, MediaType destination, Marshaller marshaller); static byte[] convertJavaToOctetStream(Object source, MediaType sourceMediaType, Marshaller marshaller); static byte[] convertJavaToProtoStream(Object source, MediaType sourceMediaType, ImmutableSerializationContext ctx); static byte[] convertJavaToText(Object source, MediaType sourceMediaType, MediaType destinationMediaType); static Object decodeObjectContent(Object content, MediaType contentMediaType); static byte[] convertCharset(Object content, Charset fromCharset, Charset toCharset); static byte[] decodeOctetStream(Object input, MediaType octetStream); static String bytesToHex(byte[] bytes); static byte[] hexToBytes(String hex); static Object convertUrlEncodedToObject(Object content); static Object convertUrlEncodedToText(Object content, MediaType destinationType); static Object convertUrlEncodedToOctetStream(Object content); static String urlEncode(Object content, MediaType mediaType); static Object urlDecode(Object content); static Object convertOctetStreamToUrlEncoded(Object content, MediaType contentType); }
StandardConversions { public static String convertTextToObject(Object source, MediaType sourceType) { if (source == null) return null; if (source instanceof String) return source.toString(); if (source instanceof byte[]) { byte[] bytesSource = (byte[]) source; return new String(bytesSource, sourceType.getCharset()); } throw CONTAINER.invalidTextContent(source); }  static Object convertTextToText(Object source, MediaType sourceType, MediaType destinationType); static byte[] convertTextToOctetStream(Object source, MediaType sourceType); static String convertTextToObject(Object source, MediaType sourceType); static String convertTextToUrlEncoded(Object source, MediaType sourceType); static byte[] convertOctetStreamToText(byte[] source, MediaType destination); static Object convertOctetStreamToJava(byte[] source, MediaType destination, Marshaller marshaller); static byte[] convertJavaToOctetStream(Object source, MediaType sourceMediaType, Marshaller marshaller); static byte[] convertJavaToProtoStream(Object source, MediaType sourceMediaType, ImmutableSerializationContext ctx); static byte[] convertJavaToText(Object source, MediaType sourceMediaType, MediaType destinationMediaType); static Object decodeObjectContent(Object content, MediaType contentMediaType); static byte[] convertCharset(Object content, Charset fromCharset, Charset toCharset); static byte[] decodeOctetStream(Object input, MediaType octetStream); static String bytesToHex(byte[] bytes); static byte[] hexToBytes(String hex); static Object convertUrlEncodedToObject(Object content); static Object convertUrlEncodedToText(Object content, MediaType destinationType); static Object convertUrlEncodedToOctetStream(Object content); static String urlEncode(Object content, MediaType mediaType); static Object urlDecode(Object content); static Object convertOctetStreamToUrlEncoded(Object content, MediaType contentType);  }