gitlab4j-api icon indicating copy to clipboard operation
gitlab4j-api copied to clipboard

Object Attributes

Open bdgould opened this issue 1 year ago • 12 comments

I keep getting MergeRequestEvent having a null objectAttributes field. It looks like the API actually uses the syntax: object_attributes. This seems to fix it. There could be other instances of elsewhere in the API.

I'm trying create a simple webhook trigger using a managed GitLab CE 17.5.1 server, and am getting event json like: sample.json

bdgould avatar Nov 24 '24 18:11 bdgould

How are you using this library?

Because the convention of turning underscore notation to camelCase should work out of the box, without us having to redefine it everywhere using a @JsonProperty property annotation.

This is also covered by Unit Tests here: https://github.com/gitlab4j/gitlab4j-api/blob/0a1b6e0dcc926bb9fa1fb284d12b89388f446548/src/test/java/org/gitlab4j/api/TestGitLabApiEvents.java

So I guess that you have a different jackson config (maybe a different ObjectMapper instance).

jmini avatar Nov 28 '24 08:11 jmini

When I have deleted the 6.x branch (see https://github.com/gitlab4j/gitlab4j-api/issues/926#issuecomment-2506771237) this PR was closed, but this is not my intention. It can be changed to target main (which is the branch where the next 6.0.0 version is prepared).

jmini avatar Nov 29 '24 07:11 jmini

I think the configuration is done here:

https://github.com/gitlab4j/gitlab4j-api/blob/e71f22bae191d10ba8b0fffe1df1a571f7285917/gitlab4j-api/src/main/java/org/gitlab4j/api/utils/JacksonJson.java#L63

To configure the ObjectMapper that does the case transformation inside a Quarkus project you need to do this:

import javax.enterprise.inject.Instance;
import javax.inject.Singleton;

import org.gitlab4j.api.utils.JacksonJson;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import io.quarkus.jackson.ObjectMapperCustomizer;

public class ObjectMapperConfiguration {

	@Singleton
	ObjectMapper objectMapper(Instance<ObjectMapperCustomizer> customizers) {
		return new JacksonJson().getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
	}
}

I am almost certain other frameworks have similar approaches.

jmini avatar Nov 29 '24 07:11 jmini

Hi @jmini , Sorry for the delay! I agree, I think the metadata would be helpful -- I was just tied up during the Thanksgiving holiday here in the U.S. and then some unrelated stuff. I can work through it a bit more here in the coming weeks!

I ran into the issue in a spring-boot application I was working through. I did quickly find the spring jackson configuration, however I ran into a somewhat related issue in that some of the event triggers for the webhook used multiple formats of Date/times... This would also be solved potentially with these style annotations. I'll take a broader swing at this!

bdgould avatar Dec 05 '24 20:12 bdgould

What a work! I will review ASAP and merge.

jmini avatar Dec 16 '24 08:12 jmini

Ha, thanks @jmini. I may need another weekend or two to test a bit more. I tried a couple different things with our managed gitlab server and found a couple date formats were wrong -- I'd like to try a test a bunch more!

bdgould avatar Dec 17 '24 14:12 bdgould

@bdgould it could even be that some date in the test JSON files in the gitlab4j-models/src/test/resources/org/gitlab4j/models folder not really matches what gitlab is sending...

jmini avatar Dec 24 '24 09:12 jmini

Yeah, I found a couple of slight issues like that. I'm just trying various things with my managed gitlab instance to verify so far.

bdgould avatar Dec 27 '24 16:12 bdgould

I fixed some more cases where the date is sent as 2018-07-01 by the server and where we were serializing as 2018-07-01T00:00:00Z in PR https://github.com/gitlab4j/gitlab4j-api/pull/1223

jmini avatar Dec 30 '24 07:12 jmini

Hello @jmini & @bdgould If this branch could be merged it would solve a lot of problems for me. Is there anything I could do to make that possible?

katrinSaleschus avatar Aug 11 '25 12:08 katrinSaleschus

@katrinSaleschus I think the work was never finished.

As discussed, I am not opposed to use Jackson annotation everywhere instead of specific ObjectMapper configuration. But the work needs to be complete and free of failure in the unit test.

Since this work was started there were a lot of changes, you need to restart where @bdgould left, fix the merge conflict and finish the open tasks.

jmini avatar Aug 20 '25 09:08 jmini

Apologies! This has definitely slipped my list. I'm hoping I can spend some hours on it in the evenings here in the next couple weeks 😄

bdgould avatar Aug 28 '25 14:08 bdgould