Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Natively support JSON.NET dynamic objects (JObject) #30

Closed
ChristianWeyer opened this issue May 2, 2013 · 13 comments
Closed

Natively support JSON.NET dynamic objects (JObject) #30

ChristianWeyer opened this issue May 2, 2013 · 13 comments

Comments

@ChristianWeyer
Copy link

On Twitter you mentioned that it should be fairly straightforward to implement via IDestructuringPolicy
;)

@kkozmic
Copy link

kkozmic commented Mar 3, 2014

I was trying to get this working via IDestructuringPolicy but, I'm afraid it won't work.

Cursory look through the codebase seems to indicate (here https://github.com/serilog/serilog/blob/master/src/Serilog/Parameters/PropertyValueConverter.cs?source=c#L112) that PropertyValueConverterfirst treats the objects as a collection (all JTokens are IEnumerable) and therefore never bothers checking with IDestructuringPolicy.

I think perhaps giving the IDestructuringPolicy a higher priority (checking with it first, and then falling back to the default behaviour) might offer a way out, but I may be completeley wrong, I only spent 2 minutes looking at this code.

@kkozmic
Copy link

kkozmic commented Mar 3, 2014

I created a quick workaround for now by... adding a level of indirection.

I added a class called JObjectWrapper that is not IEnumerable and I wrap my JObject with it. Now my IDestructuringPolicy gets called and the world is a happy place again.

@nblumhardt
Copy link
Member

@kkozmic how's this one turning out? Worth us removing the limitation you mention above? Any other thoughts? Cheers :)

@kkozmic
Copy link

kkozmic commented Apr 7, 2014

well, it's a nasty workaround :) It gets me where I need to be but I'd rather have a more elegant solution than that if possible.

@Jaben
Copy link
Member

Jaben commented May 18, 2014

New interface, perhaps?

public interface ISequenceConversionPolicy
{
   bool TryConvertToSequence(object value, ILogEventPropertyValueFactory propertyValueFactory, out SequenceValue result);
}

Also, maybe:

public interface IDictionaryConversionPolicy

:)

@nblumhardt
Copy link
Member

Closing for now, but open to working through this one if anyone's keen to try a PR. Thanks for all the input folks! :)

@mcintyre321
Copy link
Contributor

@kkozmic Any chance I could take a look at your IDestructuringPolicy (the one that works with the wrapper)?

@kkozmic
Copy link

kkozmic commented Feb 2, 2015

Sorry, I don't have that code with me anymore.

On Tue Feb 03 2015 at 4:38:45 AM Harry McIntyre notifications@github.com
wrote:

@kkozmic https://github.com/kkozmic Any chance I could take a look at
your IDestructuringPolicy (the one that works with the wrapper)?


Reply to this email directly or view it on GitHub
#30 (comment).

@nblumhardt
Copy link
Member

#371 echoes this one, I think it's one for us to reopen, but might be a "2.0"

@nblumhardt nblumhardt reopened this Feb 2, 2015
Jaben added a commit to Jaben/serilog that referenced this issue Feb 3, 2015
… run before IEnumerable cast -- allowing an opportunity for policies to support IEnumerable values. Added IsValueTypeDictionary function to simplify the look of the dictionary conversion code.
@nblumhardt
Copy link
Member

Build 1.4.168 removes the limitation that made this awkward; would love to see a Serilog.Extras.JObject or similar that takes advantage of it :-)

Thanks @Jaben for nailing this!

@nblumhardt
Copy link
Member

https://github.com/destructurama/json-net

@mcintyre321
Copy link
Contributor

Nice!

@CumpsD
Copy link

CumpsD commented Dec 22, 2015

@nblumhardt that's awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants