@Override public BufferedImage deserialize( final JsonParser parser, final DeserializationContext context) throws IOException, JsonProcessingException { final InputStream is = new ByteArrayInputStream(parser.getBinaryValue()); return ImageIO.read(is); }
public void testBinary() throws Exception { ObjectMapper mapper = new ObjectMapper(); final int LENGTH = 13045; byte[] data = new byte[LENGTH]; for (int i = 0; i < LENGTH; ++i) { data[i] = (byte) i; } StringWriter sw = new StringWriter(); mapper.writeValue(sw, BinaryNode.valueOf(data)); JsonParser p = new JsonFactory().createParser(sw.toString()); // note: can't determine it's binary from json alone: assertToken(JsonToken.VALUE_STRING, p.nextToken()); assertArrayEquals(data, p.getBinaryValue()); p.close(); }
private void handleNewMembership(String path, SqlSession sql, JsonParser input) throws IOException, EngineException { JsonUtils.nextExpect(input, "entity"); long entityId = input.getLongValue(); JsonUtils.nextExpect(input, "groupId"); input.getLongValue(); // we ignore this JsonUtils.nextExpect(input, "contents"); byte[] contents = input.getBinaryValue(); GroupMembership parsed = groupMembershipSerializer.fromJson(contents, entityId, path); dbGroups.addMemberFromParent( path, new EntityParam(entityId), parsed.getRemoteIdp(), parsed.getTranslationProfile(), parsed.getCreationTs(), sql); JsonUtils.nextExpect(input, JsonToken.END_OBJECT); }
public byte[] deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext) { JsonToken localJsonToken1 = paramJsonParser.getCurrentToken(); if (localJsonToken1 == JsonToken.VALUE_STRING) return paramJsonParser.getBinaryValue(paramDeserializationContext.getBase64Variant()); if (localJsonToken1 == JsonToken.VALUE_EMBEDDED_OBJECT) { Object localObject2 = paramJsonParser.getEmbeddedObject(); if (localObject2 == null) return null; if ((localObject2 instanceof byte[])) return (byte[])localObject2; } if (!paramJsonParser.isExpectedStartArrayToken()) return handleNonArray(paramJsonParser, paramDeserializationContext); ArrayBuilders.ByteBuilder localByteBuilder = paramDeserializationContext.getArrayBuilders().getByteBuilder(); Object localObject1 = (byte[])localByteBuilder.resetAndStart(); int i = 0; JsonToken localJsonToken2 = paramJsonParser.nextToken(); int j; label130: int k; if (localJsonToken2 != JsonToken.END_ARRAY) if ((localJsonToken2 == JsonToken.VALUE_NUMBER_INT) || (localJsonToken2 == JsonToken.VALUE_NUMBER_FLOAT)) { j = paramJsonParser.getByteValue(); if (i < localObject1.length) break label214; byte[] arrayOfByte = (byte[])localByteBuilder.appendCompletedChunk(localObject1, i); k = 0; localObject1 = arrayOfByte; } while (true) { i = k + 1; localObject1[k] = j; break; if (localJsonToken2 != JsonToken.VALUE_NULL) throw paramDeserializationContext.mappingException(this._valueClass.getComponentType()); j = 0; break label130; return (byte[])localByteBuilder.completeAndClearBuffer(localObject1, i); label214: k = i; } }