com.fasterxml.jackson.core.Base64Variants Java Examples
The following examples show how to use
com.fasterxml.jackson.core.Base64Variants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectMapperUtil.java From endpoints-java with Apache License 2.0 | 7 votes |
/** * Creates an Endpoints standard object mapper that allows unquoted field names and unknown * properties. * * Note on unknown properties: When Apiary FE supports a strict mode where properties * are checked against the schema, BE can just ignore unknown properties. This way, FE does * not need to filter out everything that the BE doesn't understand. Before that's done, * a property name with a typo in it, for example, will just be ignored by the BE. */ public static ObjectMapper createStandardObjectMapper(ApiSerializationConfig config) { ObjectMapper objectMapper = new ObjectMapper() .configure(JsonParser.Feature.ALLOW_COMMENTS, true) .configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true) .configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .setBase64Variant(Base64Variants.MODIFIED_FOR_URL) .setSerializerFactory( BeanSerializerFactory.instance.withSerializerModifier(new DeepEmptyCheckingModifier())); AnnotationIntrospector pair = EndpointsFlag.JSON_USE_JACKSON_ANNOTATIONS.isEnabled() ? AnnotationIntrospector.pair( new ApiAnnotationIntrospector(config), new JacksonAnnotationIntrospector()) : new ApiAnnotationIntrospector(config); objectMapper.setAnnotationIntrospector(pair); return objectMapper; }
Example #2
Source File: AuthScheme.java From tindroid with Apache License 2.0 | 6 votes |
public static String[] decodeBasicToken(String token) { String basicToken; // Decode base64 string basicToken = new String(Base64Variants.getDefaultVariant().decode(token), StandardCharsets.UTF_8); // Split "login:password" into parts. int splitAt = basicToken.indexOf(':'); if (splitAt <= 0) { return null; } return new String[] { basicToken.substring(0, splitAt), splitAt == basicToken.length() - 1 ? "" : basicToken.substring(splitAt+1, basicToken.length()-1) }; }
Example #3
Source File: JSON.java From rapidoid with Apache License 2.0 | 6 votes |
private static ObjectMapper prettyMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL); mapper.configure(SerializationFeature.INDENT_OUTPUT, true); mapper.registerModule(tuuidModule()); if (!Env.dev()) { mapper.registerModule(new AfterburnerModule()); } DefaultPrettyPrinter pp = new DefaultPrettyPrinter(); pp = pp.withObjectIndenter(new DefaultIndenter(" ", "\n")); mapper.setDefaultPrettyPrinter(pp); return mapper; }
Example #4
Source File: StoredAsJsonDeserializer.java From Rosetta with Apache License 2.0 | 6 votes |
@Override public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JavaType javaType = ctxt.getTypeFactory().constructType(type); ObjectMapper mapper = (ObjectMapper) jp.getCodec(); if (jp.getCurrentToken() == JsonToken.VALUE_STRING) { return deserialize(mapper, jp.getText(), javaType); } else if (jp.getCurrentToken() == JsonToken.VALUE_EMBEDDED_OBJECT) { String json = new String(jp.getBinaryValue(Base64Variants.getDefaultVariant()), StandardCharsets.UTF_8); return deserialize(mapper, json, javaType); } else if(jp.getCurrentToken() == JsonToken.START_OBJECT || jp.getCurrentToken() == JsonToken.START_ARRAY) { return mapper.readValue(jp, javaType); } else { throw ctxt.mappingException("Expected JSON String"); } }
Example #5
Source File: BlockJsonSerde.java From presto with Apache License 2.0 | 5 votes |
@Override public void serialize(Block block, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { // Encoding name is length prefixed as are many block encodings SliceOutput output = new DynamicSliceOutput(toIntExact(block.getSizeInBytes() + block.getEncodingName().length() + (2 * Integer.BYTES))); writeBlock(blockEncodingSerde, output, block); Slice slice = output.slice(); jsonGenerator.writeBinary(Base64Variants.MIME_NO_LINEFEEDS, slice.byteArray(), slice.byteArrayOffset(), slice.length()); }
Example #6
Source File: BlockJsonSerde.java From presto with Apache License 2.0 | 5 votes |
@Override public Block deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { byte[] decoded = jsonParser.getBinaryValue(Base64Variants.MIME_NO_LINEFEEDS); return readBlock(blockEncodingSerde, Slices.wrappedBuffer(decoded)); }
Example #7
Source File: UUIDDeserializer.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected UUID _deserialize(String id, DeserializationContext ctxt) throws IOException { // Adapted from java-uuid-generator (https://github.com/cowtowncoder/java-uuid-generator) // which is 5x faster than UUID.fromString(value), as oper "ManualReadPerfWithUUID" if (id.length() != 36) { /* 14-Sep-2013, tatu: One trick we do allow, Base64-encoding, since we know * length it must have... */ if (id.length() == 24) { byte[] stuff = Base64Variants.getDefaultVariant().decode(id); return _fromBytes(stuff, ctxt); } return _badFormat(id, ctxt); } // verify hyphens first: if ((id.charAt(8) != '-') || (id.charAt(13) != '-') || (id.charAt(18) != '-') || (id.charAt(23) != '-')) { _badFormat(id, ctxt); } long l1 = intFromChars(id, 0, ctxt); l1 <<= 32; long l2 = ((long) shortFromChars(id, 9, ctxt)) << 16; l2 |= shortFromChars(id, 14, ctxt); long hi = l1 + l2; int i1 = (shortFromChars(id, 19, ctxt) << 16) | shortFromChars(id, 24, ctxt); l1 = i1; l1 <<= 32; l2 = intFromChars(id, 28, ctxt); l2 = (l2 << 32) >>> 32; // sign removal, Java-style. Ugh. long lo = l1 | l2; return new UUID(hi, lo); }
Example #8
Source File: AuthScheme.java From tindroid with Apache License 2.0 | 5 votes |
public static String encodeBasicToken(String uname, String password) { uname = uname == null ? "" : uname; // Encode string as base64 if (uname.contains(":")) { throw new IllegalArgumentException("illegal character ':' in user name '" + uname + "'"); } password = password == null ? "" : password; return Base64Variants.getDefaultVariant().encode((uname + ":" + password).getBytes(StandardCharsets.UTF_8)); }
Example #9
Source File: AuthScheme.java From tindroid with Apache License 2.0 | 5 votes |
public static String encodeResetSecret(String scheme, String method, String value) { // Join parts using ":" then base64-encode. if (scheme == null || method == null || value == null) { throw new IllegalArgumentException("illegal 'null' parameter"); } if (scheme.contains(":") || method.contains(":") || value.contains(":")) { throw new IllegalArgumentException("illegal character ':' in parameter"); } return Base64Variants.getDefaultVariant().encode((scheme + ":" + method + ":" + value) .getBytes(StandardCharsets.UTF_8)); }
Example #10
Source File: Environments.java From beam with Apache License 2.0 | 5 votes |
public static String createStagingFileName(File path, HashCode hash) { String encodedHash = Base64Variants.MODIFIED_FOR_URL.encode(hash.asBytes()); String fileName = Files.getNameWithoutExtension(path.getAbsolutePath()); String ext = path.isDirectory() ? "jar" : Files.getFileExtension(path.getAbsolutePath()); String suffix = Strings.isNullOrEmpty(ext) ? "" : "." + ext; return String.format("%s-%s%s", fileName, encodedHash, suffix); }
Example #11
Source File: XML.java From rapidoid with Apache License 2.0 | 5 votes |
public static XmlMapper newMapper() { XmlMapper mapper = new XmlMapper(); mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); if (!Env.dev()) { mapper.registerModule(new AfterburnerModule()); } return mapper; }
Example #12
Source File: JSON.java From rapidoid with Apache License 2.0 | 5 votes |
public static ObjectMapper newMapper() { ObjectMapper mapper = new ObjectMapper(); mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.registerModule(tuuidModule()); if (!Env.dev()) { mapper.registerModule(new AfterburnerModule()); } return mapper; }
Example #13
Source File: BasicAuthHttpRequestInterceptor.java From spring-batch-lightmin with Apache License 2.0 | 4 votes |
public BasicAuthHttpRequestInterceptor(final String username, final String password) { final String authentication = username + ":" + password; encodedAuth = "Basic " + Base64Variants.MIME_NO_LINEFEEDS.encode(authentication.getBytes(StandardCharsets.US_ASCII)); }
Example #14
Source File: TypedParser.java From armeria with Apache License 2.0 | 4 votes |
@Override public ByteBuffer readFromString(String s) { return ByteBuffer.wrap(Base64Variants.getDefaultVariant().decode(s)); }