Issue with EnumDeserializer in jackson-mapper 1.9.12 version

I'm currently working on a scenario where I need to map a String to an enum Object using the Jackson ObjectMapper.readValue(String,Class) API. The issue arises when my JSON string contains a Task Object with an Action enum defined as follows:

public enum Action {

@XmlEnumValue("Add")
ADD("Add"),
@XmlEnumValue("Amend")
AMEND("Amend"),
@XmlEnumValue("Delete")
DELETE("Delete"),
@XmlEnumValue("Pending")
PENDING("Pending");
private final String value;

Action(String v) {
    value = v;
}

public String value() {
    return value;
}

public static Action fromValue(String v) {
    for (Action c: Action.values()) {
        if (c.value.equals(v)) {
            return c;
        }
    }
    throw new IllegalArgumentException(v);
}

}

When the JSON string looks like this "{"action":"Add"}", calling ObjectMapper.readValue(jsonString, Task.Class) results in org.codehaus.jackson.map.deser.StdDeserializationContext.weirdStringException(StdDeserializationContext.java:243) for the Action "Add" because it cannot convert this Enum properly.

I attempted to add a custom Deserializer, but the EnumDeserializer is still being called regardless. Does anyone have any suggestions or ideas?

All objects are generated by JAXB, so annotations are not an option in this case.

Thank you for your assistance!

Answer №1

Did you attempt the following:

Create a new ObjectMapper instance and set its AnnotationIntrospector to JaxbAnnotationIntrospector before calling readValue().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Does this Spread Operator Usage Check Out?

Upon reviewing Angular's API documentation, I came across the declaration for the clone() method in HttpRequest as follows: clone(update: { headers?: HttpHeaders; reportProgress?: boolean; params?: HttpParams; responseType?: "arraybuffer" ...

Discovering the data from a JSON serialization in JavaScript

Within my PrintViewModel list, there is a sublist called Summary. I am working with ASP.NET MVC. @model CRC.Models.PrintViewModel; <label id="lblTotalMonthlyLoanDeduction"></label> I am serializing it using JSON. var obj = @Json.Se ...

JavaScript inheritance through prototypes and the properties of objects

I am currently exploring the concept of prototyped inheritance in JavaScript for a function. This process is well documented in Wikipedia's javascript article. It functions smoothly when dealing with simple JavaScript types: function Person() { t ...

Incorporate a new data field within a JSON array

I recently received a JSON string containing an array structured like this: { "Id": 123, "Username": "Sr. X", "Packages": [ { "Name": "Cups", "SupplierId": 1, "ProviderGroupId": 575, "SupplierName": "Foo Cups" }, ...

High RAM consumption with the jQuery Vegas plugin

I've been scouring the internet, but it seems like I'm the only one facing this issue. Currently, I'm working on a website that uses the jQuery vegas plugin. However, I noticed that if I leave the page open while testing and developing, my ...

Node(Meteor) experiencing a memory leak due to setTimeout

I have encountered an unusual memory leak associated with the use of setTimeout. Every 15 seconds, I execute the following code using an async function that returns an array of promises (Promise.all). The code is supposed to run again 15 seconds after all ...

In Javascript, navigate to a specific section by scrolling down

Currently, I am in the process of enhancing my portfolio website. My goal is to incorporate a CSS class once the user scrolls to a specific section on the page. (I plan to achieve this using a JavaScript event). One approach I am considering is initially ...

One way to add a JSON object to an empty JSON array using Javascript involves pushing

Currently, I am facing an issue with an empty JSON array. shoppingCart: [] In addition to the empty array, I also have a JSON object defined as follows: let product = {"name": "name", "price": "price", "quantity": "quantity", "logoPath": "logoPath"}; M ...

Mastering the art of knowing when to implement asynchronous and synchronous programming techniques is essential for

As I explore asynchronous programming in JavaScript, I am faced with the challenge of integrating two email providers: Sendgrid and Mailgun. My goal is to send an email using one provider, and if any errors occur during the process, automatically resend th ...

The error message "NoSuchSessionError: invalid session id" pops up in Selenium, despite the fact that the application is running smoothly

Scenario and Background: I have recently developed a script to access an external website and extract specific data. The script's purpose is to retrieve grades of students and convert them into usable data for plotting. In order to streamline the dat ...

Break apart each item in the loop and create a fresh array

My JSON API response is structured like this: Array ( [sections] => Array ( [0] => Array ( [id] => 115000089967 [url] => xxxxx [html_url] => ...

What are the steps for integrating an external API into a React project?

Apologies for any potential repetition, as this question may be commonly asked. I am currently working with React, Express, CORS, node, and postgres databases. My objective is to utilize the following API to retrieve real-time prices for metals: https://me ...

Access the extended controller and call the core controller function without directly interacting with the core controller

i have a core controller that contains an array called vm.validationTypes with only 2 objects. I need to add 3 or 4 more objects to this array. to achieve this, i created another controller by extending the core controller: // CustomValidation angular.m ...

Error encountered while using XLSX.write in angular.js: n.t.match function is not recognized

I've encountered an issue while trying to generate an .xlsx file using the XLSX library. The error message I received is as follows: TypeError: n.t.match is not a function at Ps (xlsx.full.min.js:14) at Jd (xlsx.full.min.js:18) at Sv (xlsx.full.min ...

What could be the reason for the base64 returned by url-loader in webpack appearing to be

After downloading and including the url-loader for Webpack, my configuration looks like this: loaders: [ { test: /.jsx?$/, include: path.join(__dirname, './public/scripts'), loader: 'babel-loader', exclude: /node_modul ...

Elaborate on the specific error message within the .error() jQuery function

Currently, I am utilizing .error() as the callback for .post(). Here is an example of how I am using it: $.post("url", function(data){}) .error(function(){ alert("some error"); }); If an error occurs, I would like to display a detailed error ...

Transforming Data into JSON: Learn how to dynamically adjust output mappings through serialization and normalization techniques

My controller's action is as follows: public function messagesAction() { $encoders = array(new JsonEncoder()); $normalizers = array(new GetSetMethodNormalizer()); $serializer = new Serializer($normalizers, $encoders); $message = $t ...

Trigger a notification based on the selected choice

Here is some sample HTML code: <div id="hiddenDiv" style="display: none;"> <h1 id="welcomehowareyou">How are you feeling today?</h1> <select name="mood" id="mood"> <option value="" disabled selected>How are you feeling?</o ...

transforming information into hierarchical JSON format using C#

I am working with a data table that has the following structure: Table structure of given data. The table consists of four columns namely Id, Name, Salary, and RefId. In the RefId column, we store the ID of the parent object. Below is the modal class for ...

What is preventing this from retrieving the source code?

I'm trying to retrieve the HTML source code from http://yahoo.com/(index.html) and display it in a dialog box using this code snippet: $.ajax({ url: 'http://yahoo.com', success: function(data) { alert(data); } }); Unfortunately, ...