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

  • SEARCH
  • Home
  • 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 500567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:06:02+00:00 2026-05-13T06:06:02+00:00

Why is it that just when I need it, Groovy’s metaClass property returns null.

  • 0

Why is it that just when I need it, Groovy’s “metaClass” property returns null. Example:

import net.sf.json.groovy.JsonSlurper


@Grab(group='net.sf.json-lib', module='json-lib', version='2.3', classifier='jdk15')

def printMeta(obj) {

   obj.metaClass.properties.each {println "Property: ${it.name}"}
}

def raw = /{"test":"this is a test"}/

def json = new JsonSlurper().parseText(raw);
printMeta (json);

I know that JsonSlurper uses metaprogramming, so why do I get the following:

Caught: java.lang.NullPointerException: Cannot get property 'properties' on null object
at MetaTest.printMeta(MetaTest.groovy:17)
at MetaTest.run(MetaTest.groovy:24)

I’m all out of ideas.

Thanks!

  • 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-13T06:06:02+00:00Added an answer on May 13, 2026 at 6:06 am

    I’ve never played with the JSON stuff at all, but usually this happens when you’re trying to call .metaClass on a Map.

    If I don’t know the class I’m calling on beforehand, I’ll usually call .getMetaClass() specifically. Otherwise this sort of thing bites me when I’m trying to pass maps around as mock objects.

    (This is the same reason you usually want to call .getClass() instead of .class to get a Class object.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any Example suggestion that really works currently with Twitter OAuth? I just need a
I just need to know hot to create a CGLayer that has an image
Just need a little bit of Javascript to warn people that press the back
I just need help. Basically I am creating a windows appllication that sends bulk
I just realized that I need to synchronize a significant amount of data collection
Let's just say that I need to render a certain amount of HTML over
I have just heard that - push notification is possible in iPhone I need
I need a function that a user can just click a flash app button
I just have the array of 15 values that all need to be inserted
I have just found this great tutorial as it is something that I need.

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.