cloudbees-oss / zendesk-java-client

A Java client library for interacting with Zendesk
https://developer.zendesk.com/rest_api/docs/api-clients/java#zendesk-java-client-by-cloudbees
Apache License 2.0
151 stars 251 forks source link

Add TpeVoiceComment to CommentType enum #691

Closed diendanyoi54 closed 3 months ago

diendanyoi54 commented 5 months ago

I recently attempted to upgrade our Java client from 0.13.0 to 0.25.0 because of the Cursor-based pagination update on May 20, 2024 but after making the switch, errors occurred when getTicketComments was called. We have comments that implement Talk Partner Edition which saves the comment type as TpeVoiceComment but the Comment object's type field of CommentType only has VoiceComment and Comment available so when deserializing the comment it throws an error.

package org.zendesk.client.v2.model;

public enum CommentType {
    COMMENT("Comment"),
    VOICE_COMMENT("VoiceComment");

    private final String name;

    private CommentType(String name) {
        this.name = name;
    }

    public String toString() {
        return this.name;
    }
}

Steps to reproduce the behavior:

  1. Create a comment either with the API or in the GUI with type TpeVoiceComment
  2. Retrieve comment with the Cloudbees Java client using the getTicketComments method
  3. See the error:
    org.zendesk.client.v2.ZendeskException: java.lang.IllegalArgumentException: Cannot deserialize value of type org.zendesk.client.v2.model.CommentType from String "TpeVoiceComment": not one of the values accepted for Enum class: [VoiceComment, Comment]
    at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: org.zendesk.client.v2.model.Comment["type"])

When Cloudbees getTicketComments method is called, the expectation is that it will be able to properly deserialize TpeVoiceComment so it will not throw an error and instead properly return the comment.

PierreBtz commented 3 months ago

@diendanyoi54 sorry for the delay...

I don't have access to the Talk Partner Edition to check about the specifics, so I simply added the missing field value in the enum (https://github.com/cloudbees-oss/zendesk-java-client/pull/702). That would fix the issue you reported BUT I have no way to check if this is enough. Can you please test and report?

diendanyoi54 commented 3 months ago

@PierreBtz it looks good to me but I'm not sure how you would like me to test prior to something being deployed.

PierreBtz commented 3 months ago

You could build #702 and depend on it in your downstream project.

diendanyoi54 commented 3 months ago

@PierreBtz I think you're missing TpeVoiceComment from the JsonSubTypes in the Comment class (and comment extension). I added that and tested locally and it worked!

@JsonSubTypes({@Type(
    value = Comment.class,
    name = "Comment"
), @Type(
    value = VoiceComment.class,
    name = "VoiceComment"
)})
public class Comment implements Serializable {

I created a PR against your branch just to show what else I added with no expectation of you merging it with your's. However, I did verify the code in my PR worked 😄 .

PierreBtz commented 3 months ago

@diendanyoi54 thanks, I commented on the PR? I believe we can amend this one with:

@JsonTypeInfo(use = NAME, include = EXTERNAL_PROPERTY, property = "type", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = Comment.class, name = "Comment"),
  @JsonSubTypes.Type(value = VoiceComment.class, name = "VoiceComment"),
  @JsonSubTypes.Type(value = VoiceComment.class, name = "TpeVoiceComment")
})
public class Comment implements Serializable {