aboutsummaryrefslogtreecommitdiffstats
path: root/flags/src/main/java/com/yahoo/vespa/flags/json/wire/WireFlagDataList.java
blob: e7c3ce1a6f6ec8a0131bd430fc9af478ad1edea0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.flags.json.wire;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import static com.yahoo.yolean.Exceptions.uncheck;

/**
 * @author hakonhall
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class WireFlagDataList {
    @JsonProperty("flags")
    public List<WireFlagData> flags = new ArrayList<>();

    private static final ObjectMapper mapper = new ObjectMapper();

    public void serializeToOutputStream(OutputStream outputStream) {
        uncheck(() -> mapper.writeValue(outputStream, this));
    }

    public byte[] serializeToBytes() {
        return uncheck(() -> mapper.writeValueAsBytes(this));
    }

    public static WireFlagDataList deserializeFrom(byte[] bytes) {
        return uncheck(() -> mapper.readValue(bytes, WireFlagDataList.class));
    }
}