All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getstream.client.model.activities.ActivitySignedRecipientDeserializer Maven / Gradle / Ivy

There is a newer version: 2.1.3
Show newest version
package io.getstream.client.model.activities;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

/**
 * Jackson's custom deserializer is designed to handle responses containing signed recipients.
 * As response of adding activities, GetStream.io returns signed recipients contained
 * into a nested array, e.g.:
*
 * "to": [
 *   [
 *     "user:1",
 *     "6mQhuzQ79e0rZ17bSq1CCxXoRac"
 *   ],
 *   [
 *     "user:2",
 *     "6mQhuzQ79e0rZ17bSq1CCxJu788"
 *   ]
 * ]
 * 
*
* This deserializer parses the nested array and returns collapsed entries like those:
*
 * "to": [
 *   "user:1 6mQhuzQ79e0rZ17bSq1CCxXoRac",
 *   "user:2 6mQhuzQ79e0rZ17bSq1CCxJu788"
 * ]
 * 
*/ public class ActivitySignedRecipientDeserializer extends JsonDeserializer { @Override public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { String value = null; if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) { value = String.format("%s %s", jsonParser.nextTextValue(), jsonParser.nextTextValue()); jsonParser.nextToken(); } else { value = jsonParser.getValueAsString(); } return value; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy