summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/result/FeatureData.java
blob: 53e77631ff97982edc26665c23dd4d788e41197d (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
38
39
40
41
42
43
44
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.result;

import com.yahoo.data.access.Inspector;
import com.yahoo.data.access.Inspectable;
import com.yahoo.data.access.Type;
import com.yahoo.data.JsonProducer;
import com.yahoo.data.access.simple.JsonRender;

/**
 * A wrapper for structured data representing feature values.
 */
public class FeatureData implements Inspectable, JsonProducer {

    private final Inspector value;

    public FeatureData(Inspector value) {
        this.value = value;
    }

    @Override
    public Inspector inspect() {
        return value;
    }

    public String toString() {
        if (value.type() == Type.EMPTY) {
            return "";
        } else {
            return toJson();
        }
    }

    @Override
    public String toJson() {
        return writeJson(new StringBuilder()).toString();
    }

    @Override
    public StringBuilder writeJson(StringBuilder target) {
        return JsonRender.render(value, target, true);
    }

}