On Tue, Sep 25, 2018 at 4:42 PM ASHWINI RAI <babu.bh...@gmail.com> wrote:
>
> Hi Everyone,
>
> I have written a custom deserializer for my application. My api spec has 
> "Balance" field and it is defined as double. But when I return this from my 
> api using jackson 2.9.0 I want 25000 to be returned as 25000.00 and likewise 
> for all output.
>
> I am able to achieve this using :
> jgen.writeString(output);
>
> But this will make it a String i.e:
>
> "Balance": "25000.00"
>
> When I use
> jgen.writeNumber(output);
> It removes the insignificant 0.
>
> I want the output to be like:
>
> "Balance": 25000.00
>
> Can anyone confirm if this is a limitation in Jackson, or if this is not then 
> how can I format my output to 2 decimal places?

There is no way to format numbers in particular way through databind API.

However, you can probably make this work with JSON by using
`writeRawValue()` method on custom serializer:
that allows you to add exact output, without double-quotes. There is
actually, I think, also
`writeNumber(String)` variant that would similarly allow outputting
anything you claim to be number, without validation.
These methods are format-specific, meaning that they may or may not
work for all format backends; they work fine with JSON.

I hope this helps,

-+Tatu +-

-- 
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 post to this group, send email to jackson-user@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to