[jackson-user] Re: convertValue ignore anySetter/anyGettter

2023-08-12 Thread 김주혁
 

Hello Ken,

To make things clear, a few questions.

   - Meaning of "to strip any additional properties before writing an 
   object". Are you looking to exclude `additionalProperties` only during 
   serialization, but include in deserialization? 
   - Is the primary intent to generate a JSON output that does not include 
   `additionalProperties`, or is there another objective? 
   - Could you also provide a simple, reproducible example using just 
   Jackson and Java?
   
Thanks,

Joo Hyuk, Kim (Vince)
On Saturday, August 12, 2023 at 1:31:13 AM UTC+9 Ken Hancock wrote:

>
> I have a pojo that serializes any additional properties into 
>
> @JsonAnyGetter
> public Map getAdditionalProperties() {
> return this.additionalProperties;
> }
>
> @JsonAnySetter
> public void setAdditionalProperty(String name, Object value) {
> this.additionalProperties.put(name, value);
> }
>
> However, I have an odd use case where I want to be able to strip any 
> additional properties before writing an object. I'm fairly sure with all of 
> Jackson's configuration settings that I should be able to configure a 
> mapper such that mapper.convertValue(myPojo, MyPojo.class) should be able 
> to serialize and deserialize back again, dropping the additionalProperties 
> when it serializes?   The pojo is deeply nested and auto-generated, so I'd 
> prefer not to hard-code having to just clear additionalProperties at each 
> sub-object.
>
> Thanks,
>
> Ken
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/bd3991ff-0120-4a10-a5d7-6e03e6e3a6d7n%40googlegroups.com.


[jackson-user] Re: Java version error with doubleparser class on java 1.8 with latest release

2023-08-11 Thread 김주혁
Did you build using an IDE? What was its configured the runtime/compiler 
version?
Build errors with such message  mostly comes from an IDE.
If IntelliJ menu is at [ File -> Project Structure -> Project Settings -> 
SDK ].

Just for a reference, I just pulled latest jackson-core:2.15 version and 
built.

[image: Untitled 2.jpg]
On Friday, August 11, 2023 at 4:50:59 PM UTC+9 jason...@fico.com wrote:

> My project is stuck on java 1.8, I cannot change that. I need to update 
> our version of jackson in order to keep up with security issues, but the 
> latest version, jackson-core-2.15.2, causes an error when I go to build the 
> application:
>
> [image: jackson-core build error.png]
>
> I know the error means that the class file, FastDoubleSwar.class, is 
> compiled for java 17 while my project is on 1.8. But the MANIFEST.MF in the 
> jackson-core jar implies that the jar is compiled/built for java 1.8. I 
> believe this issue is because the FastDoubleParser library is being pulled 
> into the jackson-core jar (see line 189 of the pom 
> 
> ).
>
> Can someone confirm this is the case? If it is the case then I imagine 
> anyone on *any older version* of Java would run into this issue on 
> 2.15.2, but the fact that this jar has been released for a while now and no 
> one (that I can find) has raised this issue makes me think it's some weird 
> configuration issue with my project.
>
> Thanks,
> ~Jason
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/20bfffd6-6986-43ea-b4e3-ff0eb6db1726n%40googlegroups.com.


Re: [jackson-user] RFE: Make MAX_ERROR_TOKEN_LENGTH configurable

2023-08-03 Thread 김주혁
This has been resolved 
by https://github.com/FasterXML/jackson-core/issues/1066, in Jackson 2.16.

On Sunday, June 11, 2023 at 2:17:20 PM UTC+9 Joo Hyuk Kim (김주혁) wrote:

> FYI, made a PR https://github.com/FasterXML/jackson-core/pull/1043 
>
> On Sunday, June 11, 2023 at 8:48:25 AM UTC+9 Tatu Saloranta wrote:
>
>> On Sat, Jun 10, 2023 at 7:04 AM Joo Hyuk Kim (김주혁)  
>> wrote: 
>> > 
>> > I will try to implement the configuration. If that's okay?  
>>
>> Absolutely! 
>>
>> -+ Tatu +- 
>>
>> > On Wednesday, June 7, 2023 at 3:53:08 AM UTC+9 Tatu Saloranta wrote: 
>> >> 
>> >> Thank you sharing this, it makes sense (wrt newly added functionality 
>> >> in location, content source). 
>> >> 
>> >> -+ Tatu +- 
>> >> 
>> >> On Tue, Jun 6, 2023 at 6:03 AM Gili Tzabari  
>> wrote: 
>> >> > 
>> >> > For what it's worth, I worked around the problem this way: 
>> >> > 
>> >> > Throwable throwable = result.getThrowable(); 
>> >> > if (throwable instanceof JsonProcessingException jpe) 
>> >> > { 
>> >> > // Jackson truncates the JSON if it's too long. Let's log the full 
>> content. 
>> >> > Object rawContent = 
>> jpe.getLocation().contentReference().getRawContent(); 
>> >> > log.error(rawContent.toString()); 
>> >> > } 
>> >> > 
>> >> > It's still ugly in the sense that there is no way to disable the 
>> original exception, so I get a truncated exception message first followed 
>> by this log. 
>> >> > 
>> >> > Gili 
>> >> > 
>> >> > On 2023-06-05 18:30, Tatu Saloranta wrote: 
>> >> > 
>> >> > There is no way to configure this currently. 
>> >> > 
>> >> > If anyone has time and interest in making this configurable I'd be 
>> >> > happy to help; it'd need to go via `JsonFactory.builder()` 
>> >> > configuration. But static config methods (static method, system 
>> >> > properties) not acceptable. 
>> >> > 
>> >> > Ideally there would probably an extensible set (similar to new 
>> >> > StreamReadConstraints setting, but different) to modify so it'd be 
>> >> > easier to add/configure different settings. 
>> >> > 
>> >> > -+ Tatu +- 
>> >> > 
>> >> > On Mon, Jun 5, 2023 at 3:24 PM Gili  wrote: 
>> >> > 
>> >> > Hi, 
>> >> > 
>> >> > When Jackson throws an exception, it quotes the JSON that triggered 
>> the exception. Unfortunately, after MAX_ERROR_TOKEN_LENGTH bytes it 
>> truncates the message so if a section of interest is further down it 
>> becomes very hard to debug. 
>> >> > 
>> >> > Is it possible to make this limit configurable? 
>> >> > 
>> >> > Thank you, 
>> >> > Gili 
>> >> > 
>> >> > -- 
>> >> > You received this message because you are subscribed to the Google 
>> Groups "jackson-user" group. 
>> >> > To unsubscribe from this group and stop receiving emails from it, 
>> send an email to jackson-user...@googlegroups.com. 
>> >> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jackson-user/9eca88c0-53dd-421e-b931-c8580c69be63n%40googlegroups.com.
>>  
>>
>> >> > 
>> >> > -- 
>> >> > You received this message because you are subscribed to the Google 
>> Groups "jackson-user" group. 
>> >> > To unsubscribe from this group and stop receiving emails from it, 
>> send an email to jackson-user...@googlegroups.com. 
>> >> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jackson-user/aaadd7bf-718c-0cc4-0619-9116912b3103%40gmail.com.
>>  
>>
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups "jackson-user" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an email to jackson-user...@googlegroups.com. 
>> > To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jackson-user/5872dc12-53bb-4d52-bd65-48cbface65efn%40googlegroups.com.
>>  
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/992257f6-a6cf-4c78-b7ea-8638198a022dn%40googlegroups.com.


[jackson-user] Re: 2.12.7 to 2.13.5 Behavioural Change

2023-06-28 Thread 김주혁
 

This is not a solution, but beware that starting from Jackson 2.10, 
`ObjectMapper.enableDefaultTyping` has been deprecated and 
`ObjectMapper.enableDefaultTyping` internally calls 
`activateDefaultTyping()`.
On Wednesday, June 28, 2023 at 4:22:40 AM UTC+9 Martin Samm wrote:

> So, i have an issue i'm struggling to resolve. I have a service making a 
> REST call to another service. Using jackson 2.12.7 all's well. Upgrading to 
> jackson 2.13.5 the same code, config etc i'm getting this error:
>
> Could not resolve subtype of [simple type, class 
> com.rapid7.platform.ipims.domain.PlatformUser]: missing type id property 
> '@class' 
>
> The PlatformUser class is a straight forward POJO (and again unchanged) 
> with the following props:
>
> private String userId;
> private Customer customer;
> private String email;
> private String oktaUserId;
> private Long createdTime;
> private Long lastLoginTime;
> private boolean multiCustomer = false;
> private boolean externalIdp;
> private Map userProperties = new HashMap<>();
>
>
> We're using a Mixin to avoid deserializing userProperties Map.
>
> Our objectMapper is setup like this:
> private ObjectMapper objectMapper() {
> ObjectMapper mapper = new ObjectMapper();
> mapper.enableDefaultTyping(
> ObjectMapper.DefaultTyping.NON_FINAL,
> JsonTypeInfo.As.PROPERTY
> );
> mapper.registerModule(new CoreJackson2Module());
> mapper.registerModule(new WebJackson2Module());
> mapper.registerModule(new WebServletJackson2Module());
> mapper.registerModule(new WebServerJackson2Module());
> mapper.registerModule(new Saml2Jackson2Module());
> mapper.registerModules(new Saml2Jackson2Module());
> mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false
> );
> // handle Java 8 Datetime with JSR-310
> mapper.registerModule(new JavaTimeModule());
> mapper.addMixIn(PlatformUser.class, PlatformUserMixin.class);
> mapper.addMixIn(MapSession.class, MapSessionMixin.class);
> return mapper;
> }
>
>
> Debugging through the code i can see the objectmapper is wired in fine and 
> that the objectMapper is setting it's valueType to a SimpleType[simple 
> type, class PlatformUser] so things seem setup correctly but at some point 
> something odd is happening and an AsPropertyTypeDeserializer is used and 
> triggers the above exception (seems to be expecting the JSON to contain an 
> @class definition/declaration, which was unnecessary previously).
>
> So, can anyone help point me in the right direction?
>
> Thanks alot.
>
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/e5661962-2d45-435e-be28-1f568808ef67n%40googlegroups.com.


Re: [jackson-user] RFE: Make MAX_ERROR_TOKEN_LENGTH configurable

2023-06-10 Thread 김주혁
FYI, made a PR https://github.com/FasterXML/jackson-core/pull/1043 

On Sunday, June 11, 2023 at 8:48:25 AM UTC+9 Tatu Saloranta wrote:

> On Sat, Jun 10, 2023 at 7:04 AM Joo Hyuk Kim (김주혁)  
> wrote:
> >
> > I will try to implement the configuration. If that's okay? 
>
> Absolutely!
>
> -+ Tatu +-
>
> > On Wednesday, June 7, 2023 at 3:53:08 AM UTC+9 Tatu Saloranta wrote:
> >>
> >> Thank you sharing this, it makes sense (wrt newly added functionality
> >> in location, content source).
> >>
> >> -+ Tatu +-
> >>
> >> On Tue, Jun 6, 2023 at 6:03 AM Gili Tzabari  
> wrote:
> >> >
> >> > For what it's worth, I worked around the problem this way:
> >> >
> >> > Throwable throwable = result.getThrowable();
> >> > if (throwable instanceof JsonProcessingException jpe)
> >> > {
> >> > // Jackson truncates the JSON if it's too long. Let's log the full 
> content.
> >> > Object rawContent = 
> jpe.getLocation().contentReference().getRawContent();
> >> > log.error(rawContent.toString());
> >> > }
> >> >
> >> > It's still ugly in the sense that there is no way to disable the 
> original exception, so I get a truncated exception message first followed 
> by this log.
> >> >
> >> > Gili
> >> >
> >> > On 2023-06-05 18:30, Tatu Saloranta wrote:
> >> >
> >> > There is no way to configure this currently.
> >> >
> >> > If anyone has time and interest in making this configurable I'd be
> >> > happy to help; it'd need to go via `JsonFactory.builder()`
> >> > configuration. But static config methods (static method, system
> >> > properties) not acceptable.
> >> >
> >> > Ideally there would probably an extensible set (similar to new
> >> > StreamReadConstraints setting, but different) to modify so it'd be
> >> > easier to add/configure different settings.
> >> >
> >> > -+ Tatu +-
> >> >
> >> > On Mon, Jun 5, 2023 at 3:24 PM Gili  wrote:
> >> >
> >> > Hi,
> >> >
> >> > When Jackson throws an exception, it quotes the JSON that triggered 
> the exception. Unfortunately, after MAX_ERROR_TOKEN_LENGTH bytes it 
> truncates the message so if a section of interest is further down it 
> becomes very hard to debug.
> >> >
> >> > Is it possible to make this limit configurable?
> >> >
> >> > Thank you,
> >> > Gili
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google 
> Groups "jackson-user" group.
> >> > To unsubscribe from this group and stop receiving emails from it, 
> send an email to jackson-user...@googlegroups.com.
> >> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/9eca88c0-53dd-421e-b931-c8580c69be63n%40googlegroups.com
> .
> >> >
> >> > --
> >> > You received this message because you are subscribed to the Google 
> Groups "jackson-user" group.
> >> > To unsubscribe from this group and stop receiving emails from it, 
> send an email to jackson-user...@googlegroups.com.
> >> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/aaadd7bf-718c-0cc4-0619-9116912b3103%40gmail.com
> .
> >
> > --
> > You received this message because you are subscribed to the Google 
> Groups "jackson-user" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to jackson-user...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/5872dc12-53bb-4d52-bd65-48cbface65efn%40googlegroups.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/bc6228a6-12f5-474e-be1d-4677d06aa7d1n%40googlegroups.com.


Re: [jackson-user] RFE: Make MAX_ERROR_TOKEN_LENGTH configurable

2023-06-10 Thread 김주혁
I will try to implement the configuration. If that's okay? 
On Wednesday, June 7, 2023 at 3:53:08 AM UTC+9 Tatu Saloranta wrote:

> Thank you sharing this, it makes sense (wrt newly added functionality
> in location, content source).
>
> -+ Tatu +-
>
> On Tue, Jun 6, 2023 at 6:03 AM Gili Tzabari  wrote:
> >
> > For what it's worth, I worked around the problem this way:
> >
> > Throwable throwable = result.getThrowable();
> > if (throwable instanceof JsonProcessingException jpe)
> > {
> > // Jackson truncates the JSON if it's too long. Let's log the full 
> content.
> > Object rawContent = jpe.getLocation().contentReference().getRawContent();
> > log.error(rawContent.toString());
> > }
> >
> > It's still ugly in the sense that there is no way to disable the 
> original exception, so I get a truncated exception message first followed 
> by this log.
> >
> > Gili
> >
> > On 2023-06-05 18:30, Tatu Saloranta wrote:
> >
> > There is no way to configure this currently.
> >
> > If anyone has time and interest in making this configurable I'd be
> > happy to help; it'd need to go via `JsonFactory.builder()`
> > configuration. But static config methods (static method, system
> > properties) not acceptable.
> >
> > Ideally there would probably an extensible set (similar to new
> > StreamReadConstraints setting, but different) to modify so it'd be
> > easier to add/configure different settings.
> >
> > -+ Tatu +-
> >
> > On Mon, Jun 5, 2023 at 3:24 PM Gili  wrote:
> >
> > Hi,
> >
> > When Jackson throws an exception, it quotes the JSON that triggered the 
> exception. Unfortunately, after MAX_ERROR_TOKEN_LENGTH bytes it truncates 
> the message so if a section of interest is further down it becomes very 
> hard to debug.
> >
> > Is it possible to make this limit configurable?
> >
> > Thank you,
> > Gili
> >
> > --
> > You received this message because you are subscribed to the Google 
> Groups "jackson-user" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to jackson-user...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/9eca88c0-53dd-421e-b931-c8580c69be63n%40googlegroups.com
> .
> >
> > --
> > You received this message because you are subscribed to the Google 
> Groups "jackson-user" group.
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to jackson-user...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jackson-user/aaadd7bf-718c-0cc4-0619-9116912b3103%40gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jackson-user+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/5872dc12-53bb-4d52-bd65-48cbface65efn%40googlegroups.com.


Re: [jackson-user] NoSuchMethodError: com.fasterxml.jackson.core.JsonParser.getReadCapabilities()

2023-06-07 Thread 김주혁
This definitely sounds like transitive dependency issue 沈.

What I can suggest (sadly not a solution) is do some searching around maven 
how to specify dep. version, override, etc..
On Wednesday, June 7, 2023 at 4:16:48 AM UTC+9 Tatu Saloranta wrote:

> On Tue, Jun 6, 2023 at 12:04 PM Ted Yu  wrote:
> >
> > Thanks for taking a look.
> >
> > The jar is produced with `maven-shade-plugin`. Do you have suggestion on 
> how I can trace down the origin of 2.6.7 databind in such scenario ?
>
> Something in Maven (etc) build would have dependency. But I am not
> sure 2.6.7 of databind should be problematic.
> `JacksonFeatureSet` was added in 2.12.0 of `jackson-core` so version
> of databind would need to be 2.12 or later (to expect it).
> So something is providing `2.6.x` of `jackson-core`; possibly shaded
> into some other artifact... so it could definitely come from
> non-jackson jar. :-(
> I don't know how to figure out where ClassLoader gets particular
> classes; chances are it's necessary to see what various jars included
> in classpath contain.
>
> -+ Tatu +-
>
> >
> > Cheers
> >
> > On Tuesday, June 6, 2023 at 11:55:07 AM UTC-7 Tatu Saloranta wrote:
> >>
> >> Version 2.6 is not supported (and hasn't for a while), so I am not
> >> sure how much we can help here with specific details.
> >>
> >> But exception message does suggest a version discrepancy: not between
> >> 2.6.7.1 and 2.6.7 (those are compatible being patch/micro-path within
> >> same minor release), but by something having later version
> >> (jackson-databind from looks) and requiring matching-or-later
> >> `jackson-core`.
> >> So you do not have a consistent set of Jackson components.
> >>
> >> -+ Tatu +-
> >>
> >> On Tue, Jun 6, 2023 at 11:52 AM Ted Yu  wrote:
> >> >
> >> > Hi,
> >> > We encounter the error shown at the end.
> >> >
> >> > Looking at 
> META-INF/maven/com.fasterxml.jackson.core/jackson-databind/pom.xml in the 
> fat jar:
> >> >
> >> > com.fasterxml.jackson.core
> >> > jackson-databind
> >> > 2.6.7.1
> >> > jackson-databind
> >> >
> >> > But I don't see 2.6.7 in any pom.xml in our repository.
> >> > I checked dependency:tree output as well.
> >> >
> >> > I wonder if someone has hint on how to find where the 2.6.7 
> dependency came in.
> >> >
> >> > Thanks
> >> >
> >> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >> > at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >> > at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >> > at java.lang.reflect.Method.invoke(Method.java:498)
> >> > at 
> org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:355)
> >> > ... 13 more
> >> > Caused by: java.util.concurrent.ExecutionException: 
> java.lang.NoSuchMethodError: 
> com.fasterxml.jackson.core.JsonParser.getReadCapabilities()Lcom\/fasterxml\/jackson\/core\/util\/JacksonFeatureSet;
> >> > at 
> java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
> >> > at 
> java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1908)
> >> > ...
> >> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >> > at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> >> > at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >> > at java.lang.reflect.Method.invoke(Method.java:498)
> >> > at 
> org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:344)
> >> > ... 31 more
> >> > Caused by: java.lang.NoSuchMethodError: 
> com.fasterxml.jackson.core.JsonParser.getReadCapabilities()Lcom\/fasterxml\/jackson\/core\/util\/JacksonFeatureSet;
> >> > at 
> com.fasterxml.jackson.databind.DeserializationContext.(DeserializationContext.java:211)
> >> > at 
> com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.(DefaultDeserializationContext.java:50)
> >> > at 
> com.fasterxml.jackson.databind.deser.DefaultDeserializationContext$Impl.(DefaultDeserializationContext.java:391)
> >> > at 
> com.fasterxml.jackson.databind.deser.DefaultDeserializationContext$Impl.createInstance(DefaultDeserializationContext.java:413)
> >> > at 
> com.fasterxml.jackson.databind.ObjectMapper.createDeserializationContext(ObjectMapper.java:4656)
> >> > at 
> com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4585)
> >> > at 
> com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3548)
> >> > at 
> com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3531)
> >> > ...
> >> > at 
> org.hibernate.metamodel.model.convert.internal.JpaAttributeConverterImpl.toDomainValue(JpaAttributeConverterImpl.java:45)
> >> > at 
> org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$2.doConversion(AttributeConverterSqlTypeDescriptorAdapter.java:140)
> >> > at 
> 

Re: [jackson-user] Expression Tree

2023-05-04 Thread 김주혁
 

I am doing quite similar stuff at my current day job 

Hope My suggestions can help.


1# “NO” to using a custom de/serializer. 
 I started using @JsonTypeInfo at work to avoid exactly that. 
 Having to write custom de/serializers for every DTO class.

2# Use Id.Name instead.

 I suggest to change DEDUCTION based handling on REST layer to 
JsonTypeInfo.Id.NAME  based. 

 This will require change in REST API specification, but in the long term 
it will be easier to debug/maintain.

 Imagine how much a troublesome it would be for a server to having to  
“assume” every time what the client intends to do with the request!


3# Maintain `@JsonSubTypes.Type.name` attribute as constants.

 Simple coding convention, maintain a variable in one place.

 Since @JsonTypeInfo provides polymorphic type handling which is already 
complex, hard-coding type id will get back to you soon. It took me only a 
few days … :(

 Take below code for example

# AS-IS

```java
@JsonSubTypes({

@JsonSubTypes.Type(value = AndDbDto.class, name = AND_VALUE),

@JsonSubTypes.Type(value = OrDbDto.class, name = OR_VALUE)

})

```

# TO-BE

```java
@JsonSubTypes({

@JsonSubTypes.Type(value = AndDbDto.class, name = AND_VALUE),

@JsonSubTypes.Type(value = OrDbDto.class, name = OR_VALUE),

@JsonSubTypes.Type(value = ConditionDbDto.class, name = 
CONDITION_VALUE)

})

public enum DbExpressions {

  AND, OR, CONITION

 // Constants

 public static final String AND_VALUE = “and”;

 public static final String OR_VALUE = “or”;

  public static final String CONDITION_VALUE = “condition”;

}
```
On Thursday, May 4, 2023 at 12:51:30 PM UTC+9 Tatu Saloranta wrote:

> On Mon, May 1, 2023 at 4:11 PM Marcus Biel  wrote:
> >
> > Hello everyone,
> >
> > I'm dealing with a project that has a complex setup, and I'm trying to 
> simplify it. Our application allows users to establish Conditions or 
> Filters in the UI. These Conditions/Filters are stored in a database and 
> can be used to limit database queries using WHERE conditions. 
> Interestingly, these filters can be built recursively from other filters.
>
> While I haven't built anything quite like this myself, I have seen
> similar use cases, for what it is worth.
> So maybe others with direct experience can share their learnings.
>
> >
> > Our current structure involves DTO classes marked with Jackson 
> annotations, which build a hierarchy. This hierarchy is mapped into 
> business objects, despite not having real business logic. These are later 
> converted into database DTOs. The system is quite intricate as it spans 
> across three layers - REST, Domain, and ORM Mapper. Additionally, the code, 
> written two years ago by another developer, extensively uses Jackson 
> Annotations, which increases the complexity and makes it difficult for me 
> to understand.
>
> Yes, that sounds like a complex beast.
>
> > Here are the two code snippets for the REST DTOs and the ORM Mapper:
> >
> > REST DTO sample:
> >
> > @JsonTypeInfo(use = DEDUCTION)
> > @JsonSubTypes({
> > @Type(AndDto.class),
> > @Type(OrDto.class),
> > @Type(ConditionDto.class),
> > @Type(FieldDto.class),
> > @Type(LabelDto.class)
> > })
> > public interface ExpressionDto {
> > }
> >
> > ORM layer DTO sample of basically the same interface:
> > @JsonTypeInfo(
> > use = JsonTypeInfo.Id.NAME,
> > property = "type")
> > @JsonSubTypes({
> > @JsonSubTypes.Type(value = AndDbDto.class, name = "and"),
> > @JsonSubTypes.Type(value = OrDbDto.class, name = "or"),
> > @JsonSubTypes.Type(value = ConditionDbDto.class, name = "condition"),
> > @JsonSubTypes.Type(value = FieldDbDto.class, name = "field"),
> > @JsonSubTypes.Type(value = LabelDBDto.class, name = "label")
> > })
> > public interface ExpressionDbData {
> > }
> >
> > ---
> > I'm faced with the task of integrating about 15 more logical operators 
> into the model, on top of the two already present - Equals for Field and 
> Contains for Labels. Incorporating these operators would significantly ramp 
> up the complexity of the existing model.
> >
> > Each field type is linked to a data type - Text, Number, or Date. Each 
> data type should support its specific logical comparison operators:
> > TEXT: EQUAL, EQUAL_IGNORE_CASE, NOT_EQUAL, START_WITH, ENDS_WITH, 
> CONTAINS
> > NUMBER: EQUAL, NOT_EQUAL, GREATER, SMALLER, GREAT_EQUAL, SMALLER_EQUAL
> > DATE: EQUAL, BEFORE, AFTER, BEFORE_OR_EQUAL, EQUAL_OR_AFTER
> >
> > I'm searching for a more straightforward yet valid method to accept 
> these conditions/filters from the frontend, store them in the database, and 
> later apply them to database queries. At present, we're achieving this with 
> a custom JPA CriteriaBuilder.
> >
> > Could using a custom Serializer / Deserializer or maybe an 
> AttributeConverter be helpful in this case? I'm not sure, and I'm open to 
> suggestions. Currently, the project is using the latest versions of Java 
> and Frameworks -