Functionality:
Implement the serialization logic for the UnregisteredMessage class that inherits from WampMessage. This implementation should correctly format the object into JSON using the provided methods.
Input/Output Requirements:
The UnregisteredMessage class must have the following constructors:
UnregisteredMessage(long requestId)
UnregisteredMessage(long requestId, @Nullable Long registrationId, @Nullable String reason)
The serialize(JsonGenerator generator) method must:
Write the message code as a number.
Write the requestId as a number.
If either registrationId or reason is present, write them as an object with:
A string field "reason" if reason is not null.
A number field "registration" if registrationId is not null.
Ensure the JSON structure adheres to the expected format without any errors.
Implement the deserialize(JsonParser jp) method as a static function to parse JSON input into an UnregisteredMessage object.
Implement getter methods:
long getRequestId();
@Nullable Long getRegistrationId();
@Nullable String getReason();
Override toString() method to return a string representation of the UnregisteredMessage object.
Ensure that all methods handle null values appropriately and do not throw unnecessary exceptions during serialization or deserialization.
Location:
Place the implemented class file in the /app/ directory. Ensure that additional dependencies, such as the WampMessage and JSON processing classes, are properly imported and utilized.
Note:
Please write unit tests to verify the correctness of the serialization and deserialization processes after implementation.