Giter VIP home page Giter VIP logo

Comments (5)

julman99 avatar julman99 commented on August 17, 2024

Hello, I'll evaluate adding that feature (automatically inject a JsonElement if specified as a parameter on the method). However, I suggest using GsonFireBuilder.registerPostProcessor since it is more flexible and decouples the post processing logic from the models. You can still have a static class inside your model to handle private fields, for example

public class MyModel {
    private String name;
    private String nameLowercase;

    public static class MyModelPostProcessor implements PostProcessor<MyModel> {

        void postDeserialize(MyModel result, JsonElement src, Gson gson) {
            result.nameLowercase = result.name.toLowerCase();
        }

        void postSerialize(JsonElement result, MyModel src, Gson gson) {
            //nothing
        }
    }
}

// In the code you initialize GsonFire
new GsonFireBuilder()
  .registerPostProcessor(MyModel.class, new MyModel.MyModelPostProcessor())

Sorry if the code above does not compiles, I did it in a plain text editor.

Let me know if that fixes your issue

from gson-fire.

molexx avatar molexx commented on August 17, 2024

The PostProcessor would do it but the @PostDeserialize annotation makes more concise and tidier code. The boilerplate of the PostProcessor static class can be skipped and it's simpler to setup the builder by calling .enableHooks() than .registerPostProcessor() because you only need to mention the Model.class, not the PostProcessor too.

(I intend to dynamically generate the calls to .enableHooks() so I don't need to manually list out all the Model classes)

Clearer and simpler code is the reason I'm attracted to gson-fire on top of standard GSON. Thanks BTW :-)

from gson-fire.

julman99 avatar julman99 commented on August 17, 2024

Hello, this enhancement was just added in 1.5.0

Let me know if it works for you. Thanks!

from gson-fire.

molexx avatar molexx commented on August 17, 2024

Hi, yes works great for me, thanks!

from gson-fire.

julman99 avatar julman99 commented on August 17, 2024

Nice!

from gson-fire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.