TeamStates { public TeamStates setStateForTeam(int teamNb, TeamState state) { ImmutableMap.Builder<Integer, TeamState> builder = ImmutableMap.builder(); teamNbToState.forEach((myTeamNb, myState) -> { if (teamNb != myTeamNb) { builder.put(myTeamNb, myState); } }); builder.put(teamNb, state); return new TeamStates(builder.build()); } TeamStates(); @JsonCreator private  TeamStates(ImmutableMap<Integer, TeamState> teamNbToState); Optional<TeamState> getStateForTeam(int teamNb); TeamStates setStateForTeam(int teamNb, TeamState state); int getNbLapsForTeam(int teamNb); @JsonValue ImmutableMap<Integer, TeamState> getTeamNbToState();  }
@Test public void testJsonSerialize_OneMember() throws Exception { TeamStates teamStates = (new TeamStates()).setStateForTeam(0, new TeamState()); assertThat(Serialization.getJsonMapper().writeValueAsString(teamStates), equalTo("{\"0\":{\"tagFragmentCount\":0}}")); }