Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:48:34+00:00 2026-05-27T04:48:34+00:00

Warning. This is a total newbie question for Groovy.. I’m from a Java background

  • 0

Warning. This is a total newbie question for Groovy.. I’m from a Java background and I don’t want to do it that way, unless I must.

I’d like to create either a mapping that will traverse one object graph easily between another object graph.

Like:

customer.contact.address.identifier = incomingContact.location.address.idCode

Both of the above object structures are completely different, with sometimes different data types. In the above snippet, identifier is a Long, and idCode is a String. Also, some of the objects are null, so I want to create sturctures on the fly.

How can this be done better with groovy’s features of closures and more functional programming?

I was originally thinking inheritence or reflection solutions to minimize if/else conditions and instanceof based programming.

Any thoughts.

Here’s some pseudo code that I started which already has smells of java:

Method call:

customer.contact.address.identifier = convert(incomingContact.location.address.idCode)

And here’s the method:

Long convert(Object fromObject) {

    //example usage that were prototyping for this method (generically)    
    //fromObject = Long.valueOf(5);
    println "convert has: [" + fromObject + "]"
    if(fromObject != null) {

      return fromObject;
    }

    return null;
 }

The above snippet has complexity and problems in itself. For one, it errors out when I want to set back the calling structure a null object, but a “Long”.

The immediate error is:

groovy.lang.MissingMethodException: No signature of method: customer.contact.address.setIdentifier() is applicable for argument types: (null) values: [null]

My alternative thought is to use a mapping tool such as: http://dozer.sourceforge.net/ and allowing it to handle traversal of both graphs, but it’s java again, which I wanted that groovy dynamic type solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:48:35+00:00Added an answer on May 27, 2026 at 4:48 am

    If you simply want to bind properties from one object to another, Groovy’s features won’t help you much. Something like Dozer might be worth a look.

    BTW, here’s a Groovier way to write the code above:

    Long convert(fromObject) {
    
      println "convert has: [" + fromObject + "]"
      fromObject as Long
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Warning:Total Rails Newb (TRN). This should be a pretty basic question so I'm hoping
Warning: This is inherited legacy code that was initially put together in the early
Warning: This question has been heavily edited. I tried my best to guess the
Is this warning anything to worry about? I've read that it can cause erratic
I get this warning from GCC: warning: cannot pass objects of non-POD type 'class
**Hello, I'm trying to create an archiver in java. This means that I am
This is the error that I am getting while using mysql_num_rows() function Error: Warning:
Warning: total rewrite. Scenario: I loaded some data from database on a TCustomADODataset descendant.
Following up on this question , it seems that the duplicate issue could be
I want to show data in this format, 12-22-2011 11:00:00 [12-22-2011 11:13:39] Warning: Contact

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.