package com.indeed.proctor.service;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.indeed.proctor.common.model.Payload;
import com.indeed.proctor.common.model.TestBucket;

/**
 * Representation of TestBucket intended for serialization into JSON.
 *
 * Mostly a rewriting of TestBucket with a few extras like skipping nulls and included test version for caching.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class JsonTestBucket {
    final private String name;
    final private int value;
    final private Object payload;
    final private int version;

    /**
     * Serializes the object using an existing bucket and a separate version.
     *
     * Version needs to be obtained outside of the bucket through ProctorResult.getTestVersions()
     */
    public JsonTestBucket(final TestBucket bucket, final int version) {
        name = bucket.getName();
        value = bucket.getValue();
        this.version = version;

        // The json serializer will automatically make this into whatever json type it should be.
        // So we don't have to worry about figuring out the type of the payload.
        // TODO: The serializer converts 0.0 to 0. Is this a problem?
        final Payload bucketPayload = bucket.getPayload();
        if (bucketPayload != null) {
            payload = bucket.getPayload().fetchAValue();
        } else {
            payload = null;
        }
    }

    public String getName() {
        return name;
    }

    public int getValue() {
        return value;
    }

    public Object getPayload() {
        return payload;
    }

    public int getVersion() {
        return version;
    }
}

package com.indeed.proctor.service;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.indeed.proctor.common.model.Payload;
import com.indeed.proctor.common.model.TestBucket;

/**
 * Representation of TestBucket intended for serialization into JSON.
 *
 * Mostly a rewriting of TestBucket with a few extras like skipping nulls and included test version for caching.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class JsonTestBucket {
    final private String name;
    final private int value;
    final private Object payload;
    final private int version;

    /**
     * Serializes the object using an existing bucket and a separate version.
     *
     * Version needs to be obtained outside of the bucket through ProctorResult.getTestVersions()
     */
    public JsonTestBucket(final TestBucket bucket, final int version) {
        name = bucket.getName();
        value = bucket.getValue();
        this.version = version;

        // The json serializer will automatically make this into whatever json type it should be.
        // So we don't have to worry about figuring out the type of the payload.
        final Payload bucketPayload = bucket.getPayload();
        if (bucketPayload != null) {
            payload = bucket.getPayload().fetchAValue();
        } else {
            payload = null;
        }
    }

    public String getName() {
        return name;
    }

    public int getValue() {
        return value;
    }

    public Object getPayload() {
        return payload;
    }

    public int getVersion() {
        return version;
    }
}

Remove serializer 0.0->0 todo. Functionality is correct.
Remove serializer 0.0->0 todo. Functionality is correct.

My JSON Firefox plugin hid the .0, making me think this was a
Jackson problem. However, Jackson is correctly outputting floats.
