0

This might seem like a strange question, but it's due to Legacy front-ends. Which consumed XML Based Beans in JSON or w/e.

We have some beans. Which are Annotated by @XMLAttribute and @XMLElement. These annotations seem to be ignored as we're updating our service's config to be annotation driven (Config used to be all XML system is >10 years old).

Now we were using a MappingJackson2HttpMessageConverter for JSON. I've disabled this and the JSON response respect the XMLElement name (some properties differ from the annotation, this was causing issues in our front-ends).

Now my last question, is it possible to get properties annotated with @XMLAttribute to return in @"key" format when using JSON.

e.g.

@XMLAttribute Long id;

Would return in JSON as {"@id":0}. Now it returns as {"id":0} Which is good, but not for us since we're stuck with a load of legacy code, of which some is not in our hands (clients using our API's).

We're changing the configs because we were not able to properly test all our code if anyone wonders.

So is returning the @value possible? Or would that mean a custom handler?

Mathijs Segers
  • 6,168
  • 9
  • 51
  • 75

1 Answers1

2

If you are using Jackson, you could use like this:

@JsonProperty("@id") Long id;

And you'll get an output like you want.

There is also this post Why are names returned with @ in JSON using Jersey - Stackoverflow that I don't know if it can be helpful for you.

I hope I have helped you!

Community
  • 1
  • 1
mifl
  • 171
  • 3