package com.fasterxml.jackson.databind.node;

import java.io.IOException;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;


/**
 * This concrete value class is used to contain boolean (true / false)
 * values. Only two instances are ever created, to minimize memory
 * usage
 */
public final class BooleanNode
    extends ValueNode
{
    // // Just need two instances...

    public final static BooleanNode TRUE = new BooleanNode();
    public final static BooleanNode FALSE = new BooleanNode();

    private BooleanNode() { }

    public static BooleanNode getTrue() { return TRUE; }
    public static BooleanNode getFalse() { return FALSE; }

    public static BooleanNode valueOf(boolean b) { return b ? TRUE : FALSE; }

    @Override
    public JsonNodeType getNodeType()
    {
        return JsonNodeType.BOOLEAN;
    }

    // Interesting... two choices...
    @Override public JsonToken asToken() {
        return (this == TRUE) ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
    }

    @Override
    public boolean booleanValue() {
        return (this == TRUE);
    }

    @Override
    public String asText() {
        return (this == TRUE) ? "true" : "false";
    }

    @Override
    public boolean asBoolean() {
        return (this == TRUE);
    }

    @Override
    public boolean asBoolean(boolean defaultValue) {
        return (this == TRUE);
    }
    
    @Override
    public int asInt(int defaultValue) {
        return (this == TRUE) ? 1 : 0;
    }
    @Override
    public long asLong(long defaultValue) {
        return (this == TRUE) ? 1L : 0L;
    }
    @Override
    public double asDouble(double defaultValue) {
        return (this == TRUE) ? 1.0 : 0.0;
    }
    
    @Override
    public final void serialize(JsonGenerator jg, SerializerProvider provider)
        throws IOException, JsonProcessingException
    {
        jg.writeBoolean(this == TRUE);
    }

    @Override
    public boolean equals(Object o)
    {
        /* Since there are only ever two instances in existence
         * can do identity comparison
         */
        return (o == this);
    }
}

@@ -472,16 +472,20 @@
 eanNode(
+true
 );%0A    p
@@ -539,16 +539,21 @@
 eanNode(
+false
 );%0A%0A    
@@ -564,23 +564,83 @@
 ate 
-BooleanNode() %7B
+final boolean _value;%0A    %0A    private BooleanNode(boolean v) %7B _value = v;
  %7D%0A%0A
@@ -886,20 +886,16 @@
 deType()
-%0A   
  %7B%0A     
@@ -937,45 +937,8 @@
  %7D%0A%0A
-    // Interesting... two choices...%0A
     
@@ -991,30 +991,22 @@
  return 
-(this == TRUE)
+_value
  ? JsonT
@@ -1114,38 +1114,30 @@
      return 
-(this == TRUE)
+_value
 ;%0A    %7D%0A%0A   
@@ -1191,30 +1191,22 @@
  return 
-(this == TRUE)
+_value
  ? %22true
@@ -1283,38 +1283,30 @@
      return 
-(this == TRUE)
+_value
 ;%0A    %7D%0A%0A   
@@ -1384,30 +1384,22 @@
  return 
-(this == TRUE)
+_value
 ;%0A    %7D%0A
@@ -1469,38 +1469,30 @@
      return 
-(this == TRUE)
+_value
  ? 1 : 0;%0A  
@@ -1564,38 +1564,30 @@
      return 
-(this == TRUE)
+_value
  ? 1L : 0L;%0A
@@ -1671,30 +1671,22 @@
  return 
-(this == TRUE)
+_value
  ? 1.0 :
@@ -1881,20 +1881,14 @@
 ean(
-this == TRUE
+_value
 );%0A 
@@ -1957,134 +1957,342 @@
     
-    /* Since there are only ever two instances in existence%0A         * can do identity comparison%0A         */
+%09/* 11-Mar-2013, tatu: Apparently ClassLoaders can manage to load%0A    %09 *    different instances, rendering identity comparisons broken.%0A    %09 *    So let's use value instead.%0A         */%0A    %09if (o == this) return true;%0A    %09if (o == null) return false;%0A    %09if (o.getClass() != getClass()) %7B%0A    %09%09return false;
 %0A    
+%09%7D%0A
     
+%09
 return (
 o ==
@@ -2287,25 +2287,50 @@
 return (
-o == this
+_value == ((BooleanNode) o)._value
 );%0A    %7D

Improve robustness of BooleanNode; sounds like version conflicts (multiple jackson jars) could cause issues with ClassLoaders