Skip to content

Jackson 3 (rc7) deserialization of class with public final Field quietly fails #5253

@tsegall

Description

@tsegall

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

The attached class works correctly on Jackson 2 - but errors on Jackson 3.

Version Information

jackson-databind-3.0.0-rc7

Reproduction

Class:

package j3bug;

import java.util.HashMap;
import java.util.Map;

public class DateTimeParserState {
	public int sampleCount;
	public int nullCount;
	public int blankCount;
	public int invalidCount;
	public final Map<String, Integer> results;

	public DateTimeParserState() {
		results = new HashMap<>();
	}
}

Driver:

package j3bug;

import java.util.Locale;

import tools.jackson.core.StreamReadFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;

public abstract class J3bug {

	public static void main(String[] args) {
		ObjectMapper mapper = JsonMapper.builder().enable(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION).build();
		DateTimeParserState state = new DateTimeParserState();
		state.results.put("hello", 1);
		String serialized = mapper.writeValueAsString(state);
		DateTimeParserState post = mapper.readValue(serialized, DateTimeParserState.class);
		if (post.results.size() != 1) {
			System.err.println("Houston, we have a problem!");
			System.exit(1);
		}
	}
}

Expected behavior

Expected Map to be restored to its former glory (i.e. one entry) when deserialized.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0Issue planned for initial 3.0 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions