Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6889499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:09:52+00:00 2026-05-27T06:09:52+00:00

I refer to this question for my classes and code, but this time with

  • 0

I refer to this question for my classes and code, but this time with another error.

I have since the above question added an empty constructor to ProtocolContainer.

The situation is now that a .NET app (C#) is creating the JSON string using DataContractJsonSerializer. The ProtocolContaier has a "SubPacket" defined as a DataPacket, and then there are subclasses to DataPacket (so this is a polymorphic problem).

The string looks like this:

{"DataPacketJSONString":null,"DataPacketType":"MyPackage.DataPackets.LoginRequestReply","MessageId":6604,"SenderUsername":null,"SubPacket":{"__type":"LoginRequestReply:#MyPackage.DataPackets","Reason":"Wrong
pass or username","Success":false,"Username":"User1"}}

Note the __type in the JSON above. That is something that .NET created to keep track of what type of object the "SubPacket" is.

The problem is how to deserialize it on the Java side, using Jackson?

It gives me the following error:

org.codehaus.jackson.map.JsonMappingException: Could not resolve type
id ‘LoginRequestReply:#MyPackage.DataPackets’ into a subtype of
[simple type, class MyPackage.DataPacket] at [Source:
java.io.StringReader@40561798; line: 1, column: 168] (through
reference chain: MyPackage.ProtocolContainer["SubPacket"])

And my guess is that Jackson can’t interpret the __type in the JSON string above. And I think that is dues to its format. The question is: how can it be resolved?

DataPacket.java – the superclass, defined in ProtocolContainer (see link above):

package MyPackage;

import org.codehaus.jackson.annotate.JsonSubTypes;
import org.codehaus.jackson.annotate.JsonTypeInfo;

import MyPackage.DataPackets.*;

@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property="__type")
@JsonSubTypes(
{
    @JsonSubTypes.Type(value = LoginRequest.class, name = "LoginRequest"),
    @JsonSubTypes.Type(value = LoginRequestReply.class, name = "LoginRequestReply")
})
public class DataPacket 
{
    
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:09:53+00:00Added an answer on May 27, 2026 at 6:09 am

    So, one solution (that I find ugly) is to adapt the JsonSubTypes so it looks the same as what is created on the C# end:

    @JsonSubTypes(
    {
        @JsonSubTypes.Type(value = LoginRequest.class, name = "LoginRequest:#MyPackage.DataPackets"),
        @JsonSubTypes.Type(value = LoginRequestReply.class, name = "LoginRequestReply:#MyPackage.DataPackets")
    })
    

    I havent found any better way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This time I have a more philosopical question. Most MVC tutorials/books seem to suggest
Variants of this question have been asked several times now here, but my question
Please refer to this background question. After constructing this COUNT, how would I then
Note: In this question I'm using the term autocomplete (or iterative search) to refer
Please refer to this post. I have become able to configure my web.config file
Please refer my previous post here . I did changes accordingly but getting error.
I think this question is quite common. Recently I have got a requirement that
This question is kind of lengthy but I try to provide you with the
Okay this is a bit of a noobish question, but I ran across this
I posted this on daniweb, but have revised my thoughts on the matter. Basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.