aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api/activity/helpers/ActivityIdDeserializer.java
blob: 69076cbcb0011dc7b414c525fa1a5459c0a10628 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.juick.server.api.activity.helpers;

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

import java.io.IOException;

public class ActivityIdDeserializer extends JsonDeserializer<String> {
    @Override
    public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        JsonToken jsonToken = p.getCurrentToken();
        if (jsonToken == JsonToken.START_OBJECT) {
            JsonNode node = p.getCodec().readTree(p);
            return node.get("id").textValue();
        }
        return p.getValueAsString();
    }
}