Skip to main content
added 23 characters in body; edited tags
Source Link
dani-vta
  • 8.6k
  • 14
  • 55
  • 69

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized, it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing, it loses the case insensitive property of the map. Does anyone know how to resolve this, or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jacksonJackson mapper property that I can use to fix this issue?

Here is some sample code:

    import com.fasterxml.jackson.core.JsonProcessingException;
    import com.fasterxml.jackson.databind.ObjectMapper;
    
    import java.util.TreeMap;
    
    public class Main {
        public static void main(String[] args) throws JsonProcessingException {
            TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
            mappings.put("Test3", "3");
            mappings.put("test1", "1");
            mappings.put("Test2", "2");
    
            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
            System.out.println(json);
            
            TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
            
            System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
        }
    }

And sample output:

    {
      "test1" : "1",
      "Test2" : "2",
      "Test3" : "3"
    }
    Deserialized map case insensitive test: null

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing it loses the case insensitive property of the map. Does anyone know how to resolve this or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jackson mapper property that I can use to fix this issue?

Here is some sample code:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        mappings.put("Test3", "3");
        mappings.put("test1", "1");
        mappings.put("Test2", "2");

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
        System.out.println(json);
        
        TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
        
        System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
    }
}

And sample output:

{
  "test1" : "1",
  "Test2" : "2",
  "Test3" : "3"
}
Deserialized map case insensitive test: null

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized, it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing, it loses the case insensitive property of the map. Does anyone know how to resolve this, or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a Jackson mapper property that I can use to fix this issue?

Here is some sample code:

    import com.fasterxml.jackson.core.JsonProcessingException;
    import com.fasterxml.jackson.databind.ObjectMapper;
    
    import java.util.TreeMap;
    
    public class Main {
        public static void main(String[] args) throws JsonProcessingException {
            TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
            mappings.put("Test3", "3");
            mappings.put("test1", "1");
            mappings.put("Test2", "2");
    
            ObjectMapper objectMapper = new ObjectMapper();
            String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
            System.out.println(json);
            
            TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
            
            System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
        }
    }

And sample output:

    {
      "test1" : "1",
      "Test2" : "2",
      "Test3" : "3"
    }
    Deserialized map case insensitive test: null
deleted 52 characters in body
Source Link
thurmc
  • 525
  • 1
  • 8
  • 34

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing this deserializes to a HashMap<String, String> instead of a TreeMap with ait loses the case insensitive lookupproperty of the map. DoesDoes anyone know how to resolve this or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jackson mapper property that I can use to fix this issue?

Here is some sample code:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        mappings.put("Test3", "3");
        mappings.put("test1", "1");
        mappings.put("Test2", "2");

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
        System.out.println(json);
        
        TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
        
        System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
    }
}

And sample output:

{
  "test1" : "1",
  "Test2" : "2",
  "Test3" : "3"
}
Deserialized map case insensitive test: null

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing this deserializes to a HashMap<String, String> instead of a TreeMap with a case insensitive lookup. Does anyone know how to resolve this or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jackson mapper property that I can use to fix this issue?

Here is some sample code:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        mappings.put("Test3", "3");
        mappings.put("test1", "1");
        mappings.put("Test2", "2");

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
        System.out.println(json);
        
        TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
        
        System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
    }
}

And sample output:

{
  "test1" : "1",
  "Test2" : "2",
  "Test3" : "3"
}
Deserialized map case insensitive test: null

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing it loses the case insensitive property of the map. Does anyone know how to resolve this or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jackson mapper property that I can use to fix this issue?

Here is some sample code:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        mappings.put("Test3", "3");
        mappings.put("test1", "1");
        mappings.put("Test2", "2");

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
        System.out.println(json);
        
        TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
        
        System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
    }
}

And sample output:

{
  "test1" : "1",
  "Test2" : "2",
  "Test3" : "3"
}
Deserialized map case insensitive test: null
added 1130 characters in body
Source Link
thurmc
  • 525
  • 1
  • 8
  • 34

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing this deserializes to a HashMap<String, String> instead of a TreeMap with a case insensitive lookup. Does anyone know how to resolve this or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jackson mapper property that I can use to fix this issue?

Here is some sample code:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        mappings.put("Test3", "3");
        mappings.put("test1", "1");
        mappings.put("Test2", "2");

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
        System.out.println(json);
        
        TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
        
        System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
    }
}

And sample output:

{
  "test1" : "1",
  "Test2" : "2",
  "Test3" : "3"
}
Deserialized map case insensitive test: null

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing this deserializes to a HashMap<String, String> instead of a TreeMap with a case insensitive lookup. Does anyone know how to resolve this or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jackson mapper property that I can use to fix this issue?

I am trying to use Jackson's ObjectMapper class to serialize an object that looks like this:

TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

but when the object is serialized it ends up looking like this:

{"mappings": {"key": "value"}}

When deserializing this deserializes to a HashMap<String, String> instead of a TreeMap with a case insensitive lookup. Does anyone know how to resolve this or possibly a type of case insensitive map class which I can use to serialize and deserialize? Is there a jackson mapper property that I can use to fix this issue?

Here is some sample code:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws JsonProcessingException {
        TreeMap<String, String> mappings = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        mappings.put("Test3", "3");
        mappings.put("test1", "1");
        mappings.put("Test2", "2");

        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(mappings);
        System.out.println(json);
        
        TreeMap<String, String> deserMappings = objectMapper.readValue(json, TreeMap.class);
        
        System.out.println("Deserialized map case insensitive test: " + deserMappings.get("test3"));
    }
}

And sample output:

{
  "test1" : "1",
  "Test2" : "2",
  "Test3" : "3"
}
Deserialized map case insensitive test: null
Source Link
thurmc
  • 525
  • 1
  • 8
  • 34
Loading