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

Issue with type based on time.Time #23

Closed
iampeter opened this issue Feb 24, 2016 · 10 comments
Closed

Issue with type based on time.Time #23

iampeter opened this issue Feb 24, 2016 · 10 comments

Comments

@iampeter
Copy link

I have a Date type:

type Date time.Time

The type is used for date-only JSON representation. I AM using a pointer to Date:

type Document struct {
   Created    *Date
}

and MergeWithOverwrite does not work unfortunately.

Could you help with this?

@darccio
Copy link
Owner

darccio commented Feb 25, 2016

Yes, sure. I'll check it this weekend.

@iampeter
Copy link
Author

Thanks @imdario

@iampeter
Copy link
Author

@imdario any luck with this? thanks

@darccio
Copy link
Owner

darccio commented Mar 1, 2016

No, sorry, I was kinda sick and I didn't have the energy to look at this. I will try this week.

@iampeter
Copy link
Author

iampeter commented Mar 1, 2016

ok thanks @imdario

@iampeter
Copy link
Author

iampeter commented Mar 5, 2016

I just tested with just *time.Time (no new type) and it seems to 'go deeper' anyway - does not overwrite.

@iampeter
Copy link
Author

iampeter commented Mar 5, 2016

@imdario, doesn't this:

    case reflect.Ptr:
        fallthrough
    case reflect.Interface:
        if src.IsNil() {
            break
        } else if dst.IsNil() {
            if dst.CanSet() && (overwrite || isEmptyValue(dst)) {
                dst.Set(src)
            }
        } else if err = deepMerge(dst.Elem(), src.Elem(), visited, depth+1, overwrite); err != nil {
            return
        }

mean that if the destination pointer exists, it will try to deep-merge anyway, instead of overwriting the whole struct the pointer points to?

@darccio
Copy link
Owner

darccio commented Mar 8, 2016

if the destination pointer exists, it will try to deep-merge anyway, instead of overwriting the whole struct the pointer points to?

Yes, you are right. "overwrite" should be used with dst.IsNil(). If dst is not nil, as in your case, it won't check if it must overwrite it anyway. Good catch! I modify it, test and push it to master.

darccio added a commit that referenced this issue Mar 8, 2016
@darccio
Copy link
Owner

darccio commented Mar 8, 2016

A little test and... Ta-da! That little sneaky bug has been fixed. Please, update your local repository and check if it works for you too.

Sorry for not being able to work on this before.

@iampeter
Copy link
Author

iampeter commented Mar 9, 2016

Great, thanks @imdario !

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

No branches or pull requests

2 participants