![]() Personally, I don't love just throwing exceptions for everything- especially things that I fully expect to fail under normal conditions, so you can return a sealed type with two variants: a success variant with your validated data type, and a failure variant with a list of errors. Jackson Annotations - JsonProperty Previous Page Next Page JsonProperty is used to mark non-standard getter/setter method to be used with respect to json property. Your validation can handle errors however you want. ![]() You can customize your serialization library to deal with these things, but the added complexity of writing custom serializers might not be worth it, and it's kind of nice to have simple DTOs that actually look like the JSON (or whatever) is nice for coming back and understanding things later. Maybe your code would benefit from using a sealed interface/class and/or value classes and/or having more nesting/grouping than the DTO. Your "domain type" can be fancier than your DTO. This approach has a couple of advantages, too: The conversion step will do the validation. ) 66 ProcessingReport report validate(message,67 findSchemaRepositories(context),68 validationContext,69 context. THEN, convert that class to a validated class for use in your code. First, use a serializable class just to make sure that the information is formatted correctly: has the right fields and basic data types. Or, to phrase it a different way: separate your input parsing into two phases. ![]() There is another module mbknor-jackson-jsonSchema that does support v4, however. Separate your data-transfer objects (DTOs) from your validation Jackson JSON Schema Module This module supports the creation of a JSON Schema (v3) Note that since JSON Schema draft version 3 and 4 are incompatible, this module CAN NOT, as-is, support v4. This means that it doesn't have to use reflection at runtime, which will make it less bug-prone (IMO) and faster. It uses annotations and a compiler hook to generate custom functions for your types at compile time.
0 Comments
Leave a Reply. |